import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const root = path.resolve(__dirname, '../..')
const srcVue = path.join(root, 'saas-companyui/src/views/company/companyWorkflow/design.vue')
const dstVue = path.join(root, 'saas-mgnui/src/views/company/companyWorkflow/design.vue')
const srcScss = path.join(root, 'saas-companyui/src/views/company/companyWorkflow/design.scss')
const dstScss = path.join(root, 'saas-mgnui/src/views/company/companyWorkflow/design.scss')
let vue = fs.readFileSync(srcVue, 'utf8')
fs.copyFileSync(srcScss, dstScss)
// toolbar: company + sales selectors
vue = vue.replace(
`
`,
`
`
)
// imports + mixin
vue = vue.replace(
`import { listAll } from '@/api/company/wxDialog';
export default {
name: 'WorkflowDesign',`,
`import { listAll } from '@/api/company/wxDialog'
import companyScopeMixin from '@/views/company/mixins/companyScopeMixin'
import { getUserList } from '@/api/company/companyUser'
export default {
name: 'WorkflowDesign',
mixins: [companyScopeMixin],`
)
// data fields
vue = vue.replace(
` // 工作流ID
workflowId: null,
// 历史版本ID`,
` // 工作流ID
workflowId: null,
// 总后台:绑定公司与销售人员
formCompanyId: null,
formCompanyUserId: null,
formSalesUserOptions: [],
// 历史版本ID`
)
// created: route companyId + scoped options
vue = vue.replace(
` created() {
this.workflowId = this.$route.params.id
this.versionId = this.$route.params.versionId`,
` created() {
this.workflowId = this.$route.params.id
this.versionId = this.$route.params.versionId
const routeCompanyId = this.$route.query.companyId
if (routeCompanyId) {
this.formCompanyId = Number(routeCompanyId)
}`
)
vue = vue.replace(
` listAll().then(e => {
this.wxDialogList = e.data;
console.log("------")
console.log(this.wxDialogList)
})`,
` this.loadWxDialogList()
if (this.formCompanyId) {
this.onDesignCompanyChange(this.formCompanyId)
}`
)
vue = vue.replace(
` // 预加载转人工分机列表(用于保存时ID→完整信息映射)
getExtensionList().then(res => {
this.easyCallExtensionList = (res.data || []).map(item => ({
...item,
_label: item.companyUserName ? \`\${item.extensionNum}-\${item.companyUserName}\` : item.extensionNum
}))
})`,
` // 预加载转人工分机列表(用于保存时ID→完整信息映射)
this.loadExtensionList()`
)
// selectNode easyCall + sms with companyId
vue = vue.replace(/getGatewayList\(\)/g, 'getGatewayList(this.resolveDesignCompanyParams())')
vue = vue.replace(/getLlmAccountList\(\)/g, 'getLlmAccountList(this.resolveDesignCompanyParams())')
vue = vue.replace(/getVoiceCodeList\(\)/g, 'getVoiceCodeList(this.resolveDesignCompanyParams())')
vue = vue.replace(/getBusiGroupList\(\)/g, 'getBusiGroupList(this.resolveDesignCompanyParams())')
vue = vue.replace(
` // 刷新分机列表(预加载已在created完成,此处刷新最新数据)
getExtensionList(this.resolveDesignCompanyParams()).then(res => {
this.easyCallExtensionList = (res.data || []).map(item => ({
...item,
_label: item.companyUserName ? \`\${item.extensionNum}-\${item.companyUserName}\` : item.extensionNum
}))
})`,
` this.loadExtensionList()`
)
vue = vue.replace(
` getSmsTempList().then(res => {
this.smsTempList = res.data || []
})`,
` getSmsTempList(this.resolveDesignCompanyParams()).then(res => {
this.smsTempList = res.data || []
})`
)
// loadWorkflow: set company from data
vue = vue.replace(
` loadWorkflow() {
getWorkflow(this.workflowId).then(res => {
const data = res.data
this.form = {`,
` loadWorkflow() {
getWorkflow(this.workflowId).then(res => {
const data = res.data
if (data.companyId) {
this.formCompanyId = data.companyId
this.onDesignCompanyChange(data.companyId)
}
if (data.companyUserId) {
this.formCompanyUserId = data.companyUserId
}
this.form = {`
)
// handleSave: validate + company fields
vue = vue.replace(
` if (!this.form.workflowName) {
this.$message.warning('请输入工作流名称')
return
}
if (!this.form.workflowName) {
this.$message.warning('请输入工作流名称')
return
}`,
` if (!this.form.workflowName) {
this.$message.warning('请输入工作流名称')
return
}
if (!this.formCompanyId) {
this.$message.warning('请选择公司')
return
}
if (!this.workflowId && !this.formCompanyUserId) {
this.$message.warning('请选择销售人员')
return
}`
)
vue = vue.replace(
` startNodeKey: startNodes[0].nodeKey,
endNodeKey: endNodes[0].nodeKey
}`,
` startNodeKey: startNodes[0].nodeKey,
endNodeKey: endNodes[0].nodeKey,
companyId: this.formCompanyId,
companyUserId: this.formCompanyUserId
}`
)
vue = vue.replace(
` this.$router.replace('/companyWx/companyWorkflow/design/' + this.workflowId)`,
` this.$router.replace({
path: '/companyWx/companyWorkflow/design/' + this.workflowId,
query: { companyId: this.formCompanyId }
})`
)
// admin helper methods
const adminMethods = `
resolveDesignCompanyParams() {
return this.formCompanyId ? { companyId: this.formCompanyId } : {}
},
onDesignCompanyChange(companyId) {
this.formCompanyUserId = null
this.loadDesignSalesUsers(companyId)
this.loadWxDialogList()
this.loadExtensionList()
},
loadDesignSalesUsers(companyId) {
if (!companyId) {
this.formSalesUserOptions = []
return
}
getUserList(companyId).then(res => {
this.formSalesUserOptions = res.data || []
})
},
loadWxDialogList() {
const params = this.resolveDesignCompanyParams()
if (!params.companyId) {
this.wxDialogList = []
return
}
listAll(params).then(e => {
this.wxDialogList = e.data || []
})
},
loadExtensionList() {
const params = this.resolveDesignCompanyParams()
if (!params.companyId) {
this.easyCallExtensionList = []
return
}
getExtensionList(params).then(res => {
this.easyCallExtensionList = (res.data || []).map(item => ({
...item,
_label: item.companyUserName ? \`\${item.extensionNum}-\${item.companyUserName}\` : item.extensionNum
}))
})
},`
vue = vue.replace(
` methods: {
// 聚焦画布容器
focusCanvasContainer() {`,
` methods: {${adminMethods}
// 聚焦画布容器
focusCanvasContainer() {`
)
fs.writeFileSync(dstVue, vue, 'utf8')
console.log('Synced design.vue and design.scss to saas-mgnui')