hookehuyr

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

......@@ -44,6 +44,7 @@
<script setup>
import { useRoute } from "vue-router";
import dayjs from "dayjs";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -69,6 +70,19 @@ const onTap = () => {
const onConfirm = ({ selectedValues, selectedOptions }) => {
props.item.value = selectedValues.join("-");
showPicker.value = false;
// 适配cookie保存未完成表单
const currentValue = selectedValues.join("-");
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 columns_type = ref([]);
......
<!--
* @Date: 2022-09-08 15:02:45
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-09 11:40:31
* @LastEditTime: 2024-11-21 09:40:49
* @FilePath: /data-table/src/components/DateTimePickerField/index.vue
* @Description: 日期时间选择器
-->
......@@ -41,6 +41,7 @@
import { useRoute } from "vue-router";
import { showToast } from "vant";
import dayjs from "dayjs";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -71,6 +72,19 @@ const onConfirm = () => {
props.item.value = `${currentDate.value.join("-")}`;
}
showPicker.value = false;
// 适配cookie保存未完成表单
const currentValue = props.item.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 }));
}
};
const onCancel = () => {
showPicker.value = false;
......
<!--
* @Date: 2022-09-14 14:44:30
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-11-21 09:32:58
* @LastEditTime: 2024-11-21 09:43:32
* @FilePath: /data-table/src/components/NumberField/index.vue
* @Description: 数字输入框
-->
......@@ -27,7 +27,6 @@
readonly
@touchstart.stop="showKeyboard($event)"
:border="false"
@blur="onBlur(item)"
>
</van-field>
<van-number-keyboard
......@@ -156,6 +155,19 @@ const blurKeyboard = () => {
document.getElementById("app").style.paddingBottom = "0";
// 还原border颜色
content.css("border-color", "#eaeaea");
// 适配cookie保存未完成表单
const currentValue = props.item.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 }));
}
};
const showDecimal = ref(false);
......@@ -196,22 +208,6 @@ const rules = [{ validator, message: validatorMessage }];
const onInput = (value) => {};
const onDelete = () => {};
// 适配cookie保存未完成表单
const onBlur = (item) => {
const currentValue = 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>
......
<!--
* @Date: 2022-08-31 11:45:30
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-08-09 11:49:07
* @LastEditTime: 2024-11-21 09:45:58
* @FilePath: /data-table/src/components/TimePickerField/index.vue
* @Description: 时间选择组件
-->
......@@ -33,6 +33,7 @@
<script setup>
import { useRoute } from "vue-router";
import dayjs from "dayjs";
import Cookies from 'js-cookie';
const $route = useRoute();
const props = defineProps({
......@@ -58,6 +59,19 @@ const onTap = () => {
const onConfirm = ({ selectedValues, selectedOptions }) => {
props.item.value = selectedValues.join(":");
showPicker.value = false;
// 适配cookie保存未完成表单
const currentValue = props.item.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 }));
}
};
const columns_type = ref([]);
......