Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2024-11-21 10:26:38 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
99f9b8b31c4d2c060cefbe5f6fad06d34b3661f1
99f9b8b3
1 parent
3029d4a7
✨ feat: 适配cookie保存未完成表单
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
src/components/RatePickerField/MyComponent.vue
src/components/TableField/index.vue
src/components/RatePickerField/MyComponent.vue
View file @
99f9b8b
<!--
* @Date: 2023-03-29 13:09:02
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 202
3-03-29 13:22:01
* @LastEditTime: 202
4-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>
...
...
src/components/TableField/index.vue
View file @
99f9b8b
<!--
* @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 = `
...
...
Please
register
or
login
to post a comment