hookehuyr

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

<!--
* @Date: 2023-03-29 13:09:02
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-03-29 13:22:01
* @LastEditTime: 2024-11-21 09:53:59
* @FilePath: /data-table/src/components/RatePickerField/MyComponent.vue
* @Description: 文件描述
-->
......@@ -22,6 +22,10 @@
import { ref } from 'vue'
import { useCustomFieldValue } from '@vant/use';
import { styleColor } from "@/constant.js";
import Cookies from 'js-cookie';
import { useRoute } from "vue-router";
const $route = useRoute();
// 获取父组件传值
const props = inject('props');
......@@ -29,6 +33,25 @@ const rate_value = ref(props.component_props.default);
// 此处传入的值会替代 Field 组件内部的 value
useCustomFieldValue(() => rate_value.value);
// 适配cookie保存未完成表单
watch(
() => rate_value.value,
(v) => {
const currentValue = v;
const existingCookie = Cookies.get($route.query.code);
if (existingCookie) {
// 如果Cookie存在,更新它
let obj = JSON.parse(existingCookie);
obj[props.key] = currentValue; // 替换掉旧值
Cookies.set($route.query.code, JSON.stringify(obj));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.key]: currentValue }));
}
}
);
</script>
<style lang="less" scoped>
......
<!--
* @Date: 2022-08-29 14:31:20
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-07 18:15:18
* @LastEditTime: 2024-11-21 10:25:09
* @FilePath: /data-table/src/components/TableField/index.vue
* @Description: 表格组件
-->
......@@ -37,6 +37,7 @@ import { showSuccessToast, showFailToast, showToast } from 'vant';
import wx from 'weixin-js-sdk'
import $ from 'jquery'
import TEditor from "@/components/TEditor/index.vue";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -96,6 +97,19 @@ const onBlur = (html) => {
value: html,
};
emit("active", props.item.value);
// 适配cookie保存未完成表单
const currentValue = html;
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 }));
}
}
// const table = `
......