Showing
2 changed files
with
33 additions
and
1 deletions
| ... | @@ -38,6 +38,7 @@ | ... | @@ -38,6 +38,7 @@ |
| 38 | <script setup> | 38 | <script setup> |
| 39 | import { useRoute } from "vue-router"; | 39 | import { useRoute } from "vue-router"; |
| 40 | import { styleColor } from "@/constant.js"; | 40 | import { styleColor } from "@/constant.js"; |
| 41 | +import Cookies from 'js-cookie'; | ||
| 41 | 42 | ||
| 42 | const $route = useRoute(); | 43 | const $route = useRoute(); |
| 43 | const props = defineProps({ | 44 | const props = defineProps({ |
| ... | @@ -84,6 +85,19 @@ const onChange = (item) => { | ... | @@ -84,6 +85,19 @@ const onChange = (item) => { |
| 84 | // 发送自定义数据结构 | 85 | // 发送自定义数据结构 |
| 85 | props.item.value = { key: props.item.key, value: gender_value.value, type: "gender" }; | 86 | props.item.value = { key: props.item.key, value: gender_value.value, type: "gender" }; |
| 86 | emit("active", props.item.value); | 87 | emit("active", props.item.value); |
| 88 | + // 适配cookie保存未完成表单 | ||
| 89 | + const currentValue = gender_value.value; | ||
| 90 | + const existingCookie = Cookies.get($route.query.code); | ||
| 91 | + | ||
| 92 | + if (existingCookie) { | ||
| 93 | + // 如果Cookie存在,更新它 | ||
| 94 | + let obj = JSON.parse(existingCookie); | ||
| 95 | + obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 96 | + Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 97 | + } else { | ||
| 98 | + // 如果Cookie不存在,新增它 | ||
| 99 | + Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 100 | + } | ||
| 87 | } | 101 | } |
| 88 | </script> | 102 | </script> |
| 89 | 103 | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-14 14:44:30 | 2 | * @Date: 2022-09-14 14:44:30 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-28 09:55:37 | 4 | + * @LastEditTime: 2024-11-21 10:39:09 |
| 5 | * @FilePath: /data-table/src/components/IdentityField/index.vue | 5 | * @FilePath: /data-table/src/components/IdentityField/index.vue |
| 6 | * @Description: 身份证输入控件 | 6 | * @Description: 身份证输入控件 |
| 7 | --> | 7 | --> |
| ... | @@ -42,6 +42,7 @@ | ... | @@ -42,6 +42,7 @@ |
| 42 | :required="item.component_props.required" | 42 | :required="item.component_props.required" |
| 43 | :readonly="item.component_props.readonly" | 43 | :readonly="item.component_props.readonly" |
| 44 | :border="false" | 44 | :border="false" |
| 45 | + @blur="onBlur(item)" | ||
| 45 | > | 46 | > |
| 46 | <template #button> | 47 | <template #button> |
| 47 | <van-button size="small" type="primary" v-if="IdEditShow" @click="clickEdit()">编辑</van-button> | 48 | <van-button size="small" type="primary" v-if="IdEditShow" @click="clickEdit()">编辑</van-button> |
| ... | @@ -68,6 +69,7 @@ import { storeToRefs, mainStore } from "@/utils/generatePackage"; | ... | @@ -68,6 +69,7 @@ import { storeToRefs, mainStore } from "@/utils/generatePackage"; |
| 68 | import { showSuccessToast, showFailToast, showConfirmDialog } from "vant"; | 69 | import { showSuccessToast, showFailToast, showConfirmDialog } from "vant"; |
| 69 | // import idCard from "idcard"; | 70 | // import idCard from "idcard"; |
| 70 | import { styleColor } from "@/constant.js"; | 71 | import { styleColor } from "@/constant.js"; |
| 72 | +import Cookies from 'js-cookie'; | ||
| 71 | 73 | ||
| 72 | const $route = useRoute(); | 74 | const $route = useRoute(); |
| 73 | const props = defineProps({ | 75 | const props = defineProps({ |
| ... | @@ -310,6 +312,22 @@ const getGenderByIdNumber = (idNumber) => { | ... | @@ -310,6 +312,22 @@ const getGenderByIdNumber = (idNumber) => { |
| 310 | } | 312 | } |
| 311 | } | 313 | } |
| 312 | } | 314 | } |
| 315 | + | ||
| 316 | +// 适配cookie保存未完成表单 | ||
| 317 | +const onBlur = (item) => { | ||
| 318 | + const currentValue = item.value; | ||
| 319 | + const existingCookie = Cookies.get($route.query.code); | ||
| 320 | + | ||
| 321 | + if (existingCookie) { | ||
| 322 | + // 如果Cookie存在,更新它 | ||
| 323 | + let obj = JSON.parse(existingCookie); | ||
| 324 | + obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 325 | + Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 326 | + } else { | ||
| 327 | + // 如果Cookie不存在,新增它 | ||
| 328 | + Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 329 | + } | ||
| 330 | +} | ||
| 313 | </script> | 331 | </script> |
| 314 | 332 | ||
| 315 | <style lang="less" scoped> | 333 | <style lang="less" scoped> | ... | ... |
-
Please register or login to post a comment