diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index cee749c..a0235b4 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -12,11 +12,9 @@ :collapse-transition="false" mode="vertical" > - + - - diff --git a/src/utils/formBuilder.js b/src/utils/formBuilder.js index b3ed911..05b1fca 100644 --- a/src/utils/formBuilder.js +++ b/src/utils/formBuilder.js @@ -155,8 +155,8 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formItem = h(formBuilderMap(device).get(info.type), { props: { type: "datetime", - "value-format": "yyyy-MM-dd", - format: "yyyy年MM月dd日", + "value-format": "yyyy-MM-dd HH:mm:ss", + format: "yyyy-MM-dd HH:mm", value: row ? row[info.name] : this.form[info.name], clearable: true, placeholder: info.help_text, @@ -1090,6 +1090,9 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formItem = h( "van-cell", { + attrs: { + for: info.name + }, props: { title: info.label, value: this.form[info.name] ? moment(this.form[info.name]).format("YYYY年MM月DD日") : '' @@ -1101,6 +1104,9 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formItem = h( "van-cell", { + attrs: { + for: info.name + }, props: { title: info.label, value: this.form[info.name] ? moment(this.form[info.name]).format("YYYY年MM月DD日 HH时mm分ss秒") : '' @@ -1117,6 +1123,9 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formItem = h( "van-cell", { + attrs: { + for: info.name + }, props: { title: info.label, value: typeof findValue === "object" ? findValue.name : findValue @@ -1128,6 +1137,9 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab formItem = h( "van-cell", { + attrs: { + for: info.name + }, props: { title: info.label, } @@ -1208,6 +1220,9 @@ export default function formBuilder(device, info, h, row, pWrite = false,pReadab break; default: formItem = h('van-cell',{ + attrs: { + for: info.name + }, props: { title: info.label, value: row ? row[info.name] : this.form[info.name] diff --git a/src/utils/print.js b/src/utils/print.js new file mode 100644 index 0000000..52eb923 --- /dev/null +++ b/src/utils/print.js @@ -0,0 +1,41 @@ +import store from '@/store' +/** + * @param{string} printJs 打印模版 + * @param{boolean} isLog 是否带审批 + * @param{string} logContent 审批表格html + * @return{void} +**/ +export function print(printJs, isLog, logContent) { + let printStr = printJs + const regexField = /]*>(.*?)<\/field>/g; + let fieldMaths = [] + let match; + + while ((match = regexField.exec(printJs)) !== null) { + fieldMaths.push(match[0]); // 提取 之间的内容 + } + fieldMaths.forEach(fieldMath => { + const matchName = fieldMath.match(/name="([^"]+)"/); + + if (matchName) { + const nameValue = matchName[1]; + const value = store.getters.device === 'desktop' ? document.querySelector(`[for=${nameValue}]+div`).innerHTML : document.querySelector(`[for=${nameValue}] > div:nth-child(2)`).innerHTML + printStr = printStr.replace(fieldMath,`${value}`) + } else { + console.log('未找到name属性'); + } + }) + if(isLog) { + const logStyle = logContent.match(/',`${totalLogStyle}`) + const logBody = logContent.match(//g)[0] + printStr = printStr.replace('',`${logBody}`) + } + let printWindow = window.open('', '_blank'); + printWindow.document.write(printStr); + printWindow.focus(); +} diff --git a/src/views/flow/create.vue b/src/views/flow/create.vue index caf018a..7b8fd9c 100644 --- a/src/views/flow/create.vue +++ b/src/views/flow/create.vue @@ -1,12 +1,14 @@ @@ -182,11 +223,14 @@ + :flow="config.flow" + > - + @@ -198,10 +242,17 @@ import MobileForm from "./MobileForm.vue"; import assign from "./components/assign.vue"; import forward from "./components/forward.vue"; import rollback from "./components/rollback.vue"; -import { create, deal, fieldConfig, preConfig, preDeal, view } from "@/api/flow"; +import { + create, + deal, + fieldConfig, + preConfig, + preDeal, + view, +} from "@/api/flow"; import { deepCopy } from "@/utils"; import { validation, validationName } from "@/utils/validate"; - +import { print } from "@/utils/print"; export default { components: { DesktopForm, @@ -219,8 +270,8 @@ export default { config: {}, subConfig: new Map(), myStatus: new Map([ - [-2,'会签退回'], - [-1,'退回'], + [-2, "会签退回"], + [-1, "退回"], [0, "办理中"], [1, "已完成"], ]), @@ -234,31 +285,51 @@ export default { form: {}, result: {}, fileList: {}, - rules: {} + rules: {}, }; }, methods: { + async print(isLog=false) { + if(isLog) { + const res = await this.$refs['table'].exportData({ + type: 'html', + download: false + }) + print(this.config.customModel.print_format, isLog, res.content) + } else { + print(this.config.customModel.print_format, isLog) + } + }, + generateForm(object, fields) { - this.rules = {} + this.rules = {}; fields.forEach((field) => { - if(field.rules && field.rules.length > 0) { - this.rules[field.name] = field.rules.map(rule => { + if (field.rules && field.rules.length > 0) { + this.rules[field.name] = field.rules.map((rule) => { switch (rule) { - case 'required': - return { required: true, message: `请填写${field.label}`, trigger: 'blur' } + case "required": + return { + required: true, + message: `请填写${field.label}`, + trigger: "blur", + }; default: return { validator: (myRule, value, callback) => { - if(validation.get(rule).test(value)) { - callback() + if (validation.get(rule).test(value)) { + callback(); } else { - callback(new Error(`${field.label}必须为${validationName.get(rule)}`)) + callback( + new Error( + `${field.label}必须为${validationName.get(rule)}` + ) + ); } }, - trigger: 'blur' - } + trigger: "blur", + }; } - }) + }); } if (field.type === "file") { this.fileList[field.name] = []; @@ -280,7 +351,9 @@ export default { const hours = parseInt((time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60)); const seconds = (time % (1000 * 60)) / 1000; - return `${days > 0 ? (days) + '天' : ''}${hours > 0 ? (hours) + '时' : ''}${minutes}分${seconds}秒`; + return `${days > 0 ? days + "天" : ""}${ + hours > 0 ? hours + "时" : "" + }${minutes}分${seconds}秒`; }, async getConfig() { @@ -291,10 +364,10 @@ export default { background: "rgba(0, 0, 0, 0.8)", }); //路由为detail为详情 - if(/\/detail/.test(this.$route.path) && this.$route.query.flow_id) { + if (/\/detail/.test(this.$route.path) && this.$route.query.flow_id) { try { const res = await view(this.$route.query.flow_id); - console.log('view',res) + console.log("view", res); const { fields } = res?.customModel; let subFormRequest = []; const getSubForm = (id) => { @@ -422,7 +495,7 @@ export default { }, async submit(type) { - let copyForm,copyFile; + let copyForm, copyFile; if (this.device === "desktop") { copyForm = deepCopy(this.$refs["desktopForm"].form); copyFile = deepCopy(this.$refs["desktopForm"].file); @@ -430,7 +503,7 @@ export default { copyForm = deepCopy(this.$refs["mobileForm"].form); copyFile = deepCopy(this.$refs["mobileForm"].file); } - console.log(copyForm,copyFile) + console.log(copyForm, copyFile); for (let [key, value] of Object.entries(copyFile)) { if (copyForm.hasOwnProperty(key)) { copyForm[key] = value.map((i) => i.response?.id)?.toString(); @@ -455,7 +528,7 @@ export default { break; } if (this.device === "desktop") { - if(!await this.$refs['desktopForm'].validate()) return + if (!(await this.$refs["desktopForm"].validate())) return; } if (this.$route.query.flow_id) { copyForm.id = this.$route.query.flow_id; @@ -464,10 +537,14 @@ export default { copyForm ); this.result = flow; - if(!is_last_handled_log) { - await this.$alert('办理成功,其他会签办理完成后,由最后办理的成员流转到下一节点。','提示',{ - showClose: false, - }) + if (!is_last_handled_log) { + await this.$alert( + "办理成功,其他会签办理完成后,由最后办理的成员流转到下一节点。", + "提示", + { + showClose: false, + } + ); callback = () => this.$router.push("/flow/list/todo"); } } else { @@ -487,7 +564,9 @@ export default { return this.config?.customModel?.fields || []; }, readableFields() { - return /\/detail/.test(this.$route.path) ? this.fields?.map(i => i.id) : (this.config?.currentNode?.readable || []); + return /\/detail/.test(this.$route.path) + ? this.fields?.map((i) => i.id) + : this.config?.currentNode?.readable || []; }, writeableFields() { return this.config?.currentNode?.writeable || []; @@ -503,19 +582,21 @@ export default { } }, diffTime() { - return function (end,start) { - const diff = this.$moment(end).diff(this.$moment(start)) - return this.formatTime(diff) - } + return function (end, start) { + const diff = this.$moment(end).diff(this.$moment(start)); + return this.formatTime(diff); + }; }, footerData() { - const diff = this.$moment(this.config?.logs?.at(-1)?.updated_at).diff(this.$moment(this.config?.logs?.at(0)?.created_at)); + const diff = this.$moment(this.config?.logs?.at(-1)?.updated_at).diff( + this.$moment(this.config?.logs?.at(0)?.created_at) + ); return [ { seq: "总耗时", - 'use_time': this.formatTime(diff), - } - ] + use_time: this.formatTime(diff), + }, + ]; }, }, created() { @@ -547,7 +628,7 @@ export default { .container { padding: 0; } - .btns { + .btns { justify-content: space-evenly; & > * { margin: 4px 6px;