138 lines
4.3 KiB
Python
138 lines
4.3 KiB
Python
#!/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'<dict-tag\s+:options="{dt}"\s+:value="([^"]+)"\s*/>',
|
|
rf'<DictTag dict-type="{dt}" :value="\1" />',
|
|
text,
|
|
)
|
|
|
|
text = re.sub(
|
|
r"const \{ proxy \} = getCurrentInstance\(\)[^;]*;\s*\n\s*const \{ crm_[^}]+\} = toRefs<any>\(proxy[^)]+\);\s*\n",
|
|
"",
|
|
text,
|
|
flags=re.MULTILINE,
|
|
)
|
|
text = re.sub(
|
|
r"const \{ crm_[^}]+\} = toRefs<any>\(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("<pagination", "<ListPagination")
|
|
text = text.replace("</pagination>", "</ListPagination>")
|
|
|
|
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 "<script setup" in text:
|
|
text = text.replace("<script setup", f"<script setup", 1)
|
|
idx = text.find("<script setup")
|
|
end = text.find("\n", idx)
|
|
text = text[: end + 1] + SCRIPT_IMPORTS + text[end + 1 :]
|
|
|
|
if path.name in ("CustomerSelector.vue", "ContactSelector.vue", "OpportunitySelector.vue", "TinyMceEditor/index.vue"):
|
|
pass
|
|
|
|
if text != orig:
|
|
path.write_text(text, encoding="utf-8")
|
|
print(f"updated: {path.relative_to(ROOT)}")
|
|
|
|
def main():
|
|
for d in TARGET_DIRS:
|
|
if not d.exists():
|
|
continue
|
|
for path in d.rglob("*.vue"):
|
|
if "ListPagination" in str(path) or "DictTag" in str(path):
|
|
continue
|
|
migrate_file(path)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|