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-20 18:01:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b6e897c85b2acbaa51d923d71c22a2ca486a13f7
b6e897c8
1 parent
599032fb
✨ feat: 适配cookie保存未完成表单
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletions
src/components/CheckboxField/index.vue
src/components/CheckboxField/index.vue
View file @
b6e897c
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-
08-22 09:58:37
* @LastEditTime: 2024-
11-20 17:52:28
* @FilePath: /data-table/src/components/CheckboxField/index.vue
* @Description: 多项选择控件
-->
...
...
@@ -40,6 +40,8 @@
<script setup>
import { styleColor } from "@/constant.js";
import { useRoute } from "vue-router";
import Cookies from 'js-cookie';
import _ from 'lodash';
const $route = useRoute();
...
...
@@ -151,6 +153,33 @@ onMounted(() => {
props.item.value = { key: props.item.key, value: checkbox_value.value, affix: affix_value.value, type: "checkbox" };
emit("active", props.item.value);
})
// 适配cookie保存未完成表单
watch(
() => props.item.value,
(v) => {
const checkbox_value = _.cloneDeep(v.value)
checkbox_value?.forEach((element, index) => {
for (const key in v.affix) {
if (v.affix[key] && element === key) {
checkbox_value[index] = v.affix[key]
}
}
});
const currentValue = checkbox_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>
...
...
Please
register
or
login
to post a comment