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-22 10:40:02 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f242e3abe321ab06de18e0495d46d3752120f95b
f242e3ab
1 parent
d0b3cee4
fix 操作改变数值时才保存默认值
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
48 deletions
src/components/CheckboxField/index.vue
src/components/RadioField/index.vue
src/components/CheckboxField/index.vue
View file @
f242e3a
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-11-2
0 17:52:28
* @LastEditTime: 2024-11-2
2 10:33:52
* @FilePath: /data-table/src/components/CheckboxField/index.vue
* @Description: 多项选择控件
-->
...
...
@@ -104,6 +104,27 @@ const handleEmit = (item) => {
// 发送自定义数据结构
props.item.value = { key: props.item.key, value: checkbox_value.value, affix: affix_value.value, type: "checkbox" };
emit("active", props.item.value);
// 适配cookie保存未完成表单
const checkbox_v = _.cloneDeep(checkbox_value.value)
checkbox_v?.forEach((element, index) => {
for (const key in affix_value.value) {
if (affix_value.value[key] && element === key) {
checkbox_value[index] = affix_value.value[key]
}
}
});
const currentValue = checkbox_v;
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), { expires: 1 });
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }), { expires: 1 });
}
}
onMounted(() => {
// TAG:默认值处理
...
...
@@ -153,33 +174,6 @@ 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), { expires: 1 });
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }), { expires: 1 });
}
}
);
</script>
<style lang="less" scoped>
...
...
src/components/RadioField/index.vue
View file @
f242e3a
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-11-2
0 17:43:2
4
* @LastEditTime: 2024-11-2
2 10:31:5
4
* @FilePath: /data-table/src/components/RadioField/index.vue
* @Description: 单项选择控件
-->
...
...
@@ -113,6 +113,19 @@ const onChange = (item) => {
// 发送自定义数据结构
props.item.value = { key: props.item.key, value: radio_value.value, affix: affix_value.value, type: "radio" };
emit("active", props.item.value);
// 适配cookie保存未完成表单
const currentValue = affix_value.value ? affix_value.value : radio_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), { expires: 1 });
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }), { expires: 1 });
}
}
const onBlur = (item) => {
clearAffix()
...
...
@@ -174,25 +187,6 @@ const showUrl = (rule) => {
location.href = rule.desc_url
}
const rule_content = ref("");
// 适配cookie保存未完成表单
watch(
() => props.item.value,
(v) => {
const currentValue = v.affix ? v.affix : v.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), { expires: 1 });
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }), { expires: 1 });
}
}
);
</script>
<style lang="less" scoped>
...
...
Please
register
or
login
to post a comment