hookehuyr

✨ feat: 适配未完成表单功能

<!--
* @Date: 2022-08-29 14:31:20
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-19 15:22:34
* @LastEditTime: 2024-11-20 16:57:46
* @FilePath: /data-table/src/components/NameField/index.vue
* @Description: 姓名输入框
-->
......@@ -33,6 +33,8 @@
<script setup>
import { useRoute } from "vue-router";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
item: Object,
......@@ -66,6 +68,25 @@ watch(
}
}
);
// 适配cookie保存未完成表单
watch(
() => props.item.value,
(v) => {
const currentValue = 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));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }));
}
}
);
</script>
<style lang="less" scoped>
......
<!--
* @Date: 2022-08-30 11:34:19
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-22 09:55:29
* @LastEditTime: 2024-11-20 17:43:24
* @FilePath: /data-table/src/components/RadioField/index.vue
* @Description: 单项选择控件
-->
......@@ -64,6 +64,7 @@
import { styleColor } from "@/constant.js";
import $ from "jquery";
import { useRoute } from "vue-router";
import Cookies from 'js-cookie';
const $route = useRoute();
......@@ -173,6 +174,25 @@ 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));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }));
}
}
);
</script>
<style lang="less" scoped>
......
......@@ -30,6 +30,7 @@ import { useRoute } from "vue-router";
import { showSuccessToast, showFailToast } from 'vant';
// 初始化WX环境
import wx from 'weixin-js-sdk'
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -65,6 +66,25 @@ watch(
}
);
// 适配cookie保存未完成表单
watch(
() => props.item.value,
(v) => {
const currentValue = 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));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }));
}
}
);
// 默认识别类型
const scan_type_code = ref('ALL_CODE');
// 微信二维码扫描功能判断
......
<!--
* @Date: 2022-08-29 14:31:20
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-09-14 13:40:21
* @LastEditTime: 2024-11-20 17:02:26
* @FilePath: /data-table/src/components/TextareaField/index.vue
* @Description: 多行文本输入框
-->
......@@ -37,6 +37,7 @@
<script setup>
import { useRoute } from "vue-router";
import Cookies from 'js-cookie';
const props = defineProps({
item: Object,
......@@ -58,6 +59,25 @@ onMounted(() => {
// 只读模式下默认值替换换行符
props.item.value = props.item.component_props.readonly ? props.item.component_props.default?.replace(/\n/g, "<br>") : props.item.component_props.default;
})
// 适配cookie保存未完成表单
watch(
() => props.item.value,
(v) => {
const currentValue = 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));
} else {
// 如果Cookie不存在,新增它
Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue }));
}
}
);
</script>
<style lang="less" scoped>
......