Showing
1 changed file
with
25 additions
and
11 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-07-18 10:22:22 | 2 | * @Date: 2022-07-18 10:22:22 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-07-27 16:09:51 | 4 | + * @LastEditTime: 2024-07-28 18:58:31 |
| 5 | * @FilePath: /data-table/src/views/index.vue | 5 | * @FilePath: /data-table/src/views/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| 9 | <van-notice-bar v-if="formSetting.sjsj_is_count_down" left-icon="volume-o" :text="notice_text" scrollable | 9 | <van-notice-bar v-if="formSetting.sjsj_is_count_down" left-icon="volume-o" :text="notice_text" scrollable |
| 10 | mode="closeable" /> | 10 | mode="closeable" /> |
| 11 | - <div class="table-box" :style="{ margin: is_pc ? '1rem 0' : '1rem', overflow: 'auto', minWidth: is_pc ? '40rem' : '' }"> | 11 | + <div class="table-box" :style="{ margin: is_pc ? '1rem 0' : '1rem', overflow: 'auto', minWidth: (is_pc && model !== 'preview') ? '40rem' : '' }"> |
| 12 | <template v-if="PHeader.visible && page_type === 'add'"> | 12 | <template v-if="PHeader.visible && page_type === 'add'"> |
| 13 | <van-image v-if="PHeader.type === 'image' && PHeader.cover" width="100%" :src="PHeader.cover + '?imageView2/0/w/2000'" fit="cover" /> | 13 | <van-image v-if="PHeader.type === 'image' && PHeader.cover" width="100%" :src="PHeader.cover + '?imageView2/0/w/2000'" fit="cover" /> |
| 14 | <template v-if="PHeader.type === 'carousel'"> | 14 | <template v-if="PHeader.type === 'carousel'"> |
| ... | @@ -219,7 +219,7 @@ const model = $route.query.model; | ... | @@ -219,7 +219,7 @@ const model = $route.query.model; |
| 219 | * edit 编辑页 | 219 | * edit 编辑页 |
| 220 | * flow 流程页 | 220 | * flow 流程页 |
| 221 | */ | 221 | */ |
| 222 | -const page_type = $route.query.page_type ? $route.query.page_type : null; | 222 | +const page_type = $route.query.page_type ? $route.query.page_type : 'add'; |
| 223 | // | 223 | // |
| 224 | const data_id = $route.query.data_id ? $route.query.data_id : null; | 224 | const data_id = $route.query.data_id ? $route.query.data_id : null; |
| 225 | // 模仿金数据的扩展参数 | 225 | // 模仿金数据的扩展参数 |
| ... | @@ -596,19 +596,33 @@ onMounted(async () => { | ... | @@ -596,19 +596,33 @@ onMounted(async () => { |
| 596 | if (data_id) { // 如果有data_id,则获取历史数据 否则获取表单默认值 | 596 | if (data_id) { // 如果有data_id,则获取历史数据 否则获取表单默认值 |
| 597 | const history_data = await queryFormDataAPI({ form_code: $route.query.code, data_id, openid: iframe_openid }); | 597 | const history_data = await queryFormDataAPI({ form_code: $route.query.code, data_id, openid: iframe_openid }); |
| 598 | if (history_data.code) { | 598 | if (history_data.code) { |
| 599 | - let object = history_data.data; // 表单数据 | 599 | + // let object = history_data.data; // 表单数据 |
| 600 | - formData.value.forEach((item) => { // 把对应数据赋值到表单 | 600 | + // formData.value.forEach((item) => { // 把对应数据赋值到表单 |
| 601 | - for (const key in object) { | 601 | + // for (const key in object) { |
| 602 | - const element = object[key]; | 602 | + // const element = object[key]; |
| 603 | - if (item.key === key) { | 603 | + // if (item.key === key) { |
| 604 | - item.component_props.default = element; | 604 | + // item.component_props.default = element; |
| 605 | + // // 设置读写权限 read_only read_write | ||
| 606 | + // if (page_type === 'info') { | ||
| 607 | + // item.component_props.readonly = true; | ||
| 608 | + // PCommit.value.visible = false; // 只读模式下,提交按钮隐藏 | ||
| 609 | + // } | ||
| 610 | + // } | ||
| 611 | + // } | ||
| 612 | + // }); | ||
| 613 | + // 结构优化一下 | ||
| 614 | + let object = history_data.data; | ||
| 615 | + const isInfoPage = page_type === 'info'; | ||
| 616 | + const objectMap = new Map(Object.entries(object)); // 将 object 转换为 Map | ||
| 617 | + formData.value.forEach((item) => { | ||
| 618 | + if (objectMap.has(item.key)) { | ||
| 619 | + item.component_props.default = objectMap.get(item.key); | ||
| 605 | // 设置读写权限 read_only read_write | 620 | // 设置读写权限 read_only read_write |
| 606 | - if (page_type === 'info') { | 621 | + if (isInfoPage) { |
| 607 | item.component_props.readonly = true; | 622 | item.component_props.readonly = true; |
| 608 | PCommit.value.visible = false; // 只读模式下,提交按钮隐藏 | 623 | PCommit.value.visible = false; // 只读模式下,提交按钮隐藏 |
| 609 | } | 624 | } |
| 610 | } | 625 | } |
| 611 | - } | ||
| 612 | }); | 626 | }); |
| 613 | historyData.value = history_data.data; // 历史表单字段数据 | 627 | historyData.value = history_data.data; // 历史表单字段数据 |
| 614 | } | 628 | } | ... | ... |
-
Please register or login to post a comment