hookehuyr

✨ feat: 适配cookie保存未完成表单

......@@ -38,6 +38,7 @@
<script setup>
import { useRoute } from "vue-router";
import { styleColor } from "@/constant.js";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -84,6 +85,19 @@ const onChange = (item) => {
// 发送自定义数据结构
props.item.value = { key: props.item.key, value: gender_value.value, type: "gender" };
emit("active", props.item.value);
// 适配cookie保存未完成表单
const currentValue = gender_value.value;
const existingCookie = Cookies.get($route.query.code);
if (existingCookie) {
// 如果Cookie存在,更新它
let obj = JSON.parse(existingCookie);
obj[props.item.key] = currentValue; // 替换掉旧值
Cookies.set($route.query.code, JSON.stringify(obj));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }));
}
}
</script>
......
<!--
* @Date: 2022-09-14 14:44:30
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-28 09:55:37
* @LastEditTime: 2024-11-21 10:39:09
* @FilePath: /data-table/src/components/IdentityField/index.vue
* @Description: 身份证输入控件
-->
......@@ -42,6 +42,7 @@
:required="item.component_props.required"
:readonly="item.component_props.readonly"
:border="false"
@blur="onBlur(item)"
>
<template #button>
<van-button size="small" type="primary" v-if="IdEditShow" @click="clickEdit()">编辑</van-button>
......@@ -68,6 +69,7 @@ import { storeToRefs, mainStore } from "@/utils/generatePackage";
import { showSuccessToast, showFailToast, showConfirmDialog } from "vant";
// import idCard from "idcard";
import { styleColor } from "@/constant.js";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -310,6 +312,22 @@ const getGenderByIdNumber = (idNumber) => {
}
}
}
// 适配cookie保存未完成表单
const onBlur = (item) => {
const currentValue = item.value;
const existingCookie = Cookies.get($route.query.code);
if (existingCookie) {
// 如果Cookie存在,更新它
let obj = JSON.parse(existingCookie);
obj[props.item.key] = currentValue; // 替换掉旧值
Cookies.set($route.query.code, JSON.stringify(obj));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }));
}
}
</script>
<style lang="less" scoped>
......