#!/usr/bin/env python3 """Migrate CRM quote Vue files to shanxia2.0 portal conventions.""" import re from pathlib import Path ROOT = Path(__file__).resolve().parents[1] TARGET_DIRS = [ ROOT / "src/views/crm/quote", ROOT / "src/components", ] DICT_TYPES = [ "crm_quote_status", "crm_product_unit", "crm_product_gg", "crm_customer_type", "crm_customer_level", "crm_industry", "crm_shfs", ] SCRIPT_IMPORTS = """import { useDictStore } from '@/store/modules/dict' import DictTag from '@/components/DictTag/index.vue' import ListPagination from '@/components/ListPagination/index.vue' import { $modal } from '@/utils/modal' """ def migrate_file(path: Path) -> None: if path.suffix != ".vue": return text = path.read_text(encoding="utf-8") orig = text text = text.replace("@/utils/ruoyi", "@/utils/format") text = text.replace("CustomerDetail", "CustomerDetailDialog") text = text.replace( "@/views/crm/customer/detail.vue", "@/views/crm/customer/CustomerDetailDialog.vue", ) text = text.replace("@/utils/request", "@/utils/http") text = text.replace("import { useDict } from '@/utils/dict';\n", "") text = text.replace("import { useDict } from '@/utils/dict'\n", "") for dt in DICT_TYPES: text = re.sub( rf'', rf'', text, ) text = re.sub( r"const \{ proxy \} = getCurrentInstance\(\)[^;]*;\s*\n\s*const \{ crm_[^}]+\} = toRefs\(proxy[^)]+\);\s*\n", "", text, flags=re.MULTILINE, ) text = re.sub( r"const \{ crm_[^}]+\} = toRefs\(proxy[^)]+\);\s*\n", "", text, ) text = text.replace( "import { listUser } from '@/api/system/user';", "import { fetchUserList } from '@/api/admin';", ) text = text.replace( "import { listUser } from '@/api/system/user'", "import { fetchUserList } from '@/api/admin'", ) text = text.replace( "import type { UserVO } from '@/api/system/user/types';", "", ) text = re.sub( r"const res = await listUser\(\{([^}]+)\}\);\s*\n\s*userList\.value = res\.rows \|\| \[\];", r"""const res = await fetchUserList({ page: 1, pageSize: 50, keyword: undefined, status: '0' }); userList.value = (res.list || []).map((u: any) => ({ userId: u.id, nickName: u.nickName, userName: u.userNo, deptName: u.deptName }));""", text, flags=re.DOTALL, ) text = text.replace("listCustomer", "fetchCustomerList") text = text.replace( "import { fetchCustomerList } from '@/api/crm/customer';", "import { fetchCustomerList } from '@/api/crm/customer';", ) text = text.replace( "from '@/api/crm/customer/types'", "from '@/api/crm/customer'", ) text = text.replace("listContact", "fetchContactList") text = text.replace( "import { fetchContactList } from '@/api/crm/customer';", "import { fetchContactList } from '@/api/contact';", ) text = text.replace("listOpportunity", "listOpportunity") text = text.replace("", "") text = text.replace("proxy?.$modal.", "$modal.") text = text.replace("proxy.$modal.", "$modal.") text = text.replace("shareDialog.shareLink = res.data;", "shareDialog.shareLink = res as string;") if "DictTag" in text and "import DictTag" not in text: if "