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 09:47:14 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8a5a5514697b38efe2eb29ddc3e9738a929c2a7a
8a5a5514
1 parent
86e6872e
✨ feat: 适配cookie保存未完成表单
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
20 deletions
src/components/DatePickerField/index.vue
src/components/DateTimePickerField/index.vue
src/components/NumberField/index.vue
src/components/TimePickerField/index.vue
src/components/DatePickerField/index.vue
View file @
8a5a551
...
...
@@ -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([]);
...
...
src/components/DateTimePickerField/index.vue
View file @
8a5a551
<!--
* @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;
...
...
src/components/NumberField/index.vue
View file @
8a5a551
<!--
* @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>
...
...
src/components/TimePickerField/index.vue
View file @
8a5a551
<!--
* @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([]);
...
...
Please
register
or
login
to post a comment