Showing
4 changed files
with
58 additions
and
20 deletions
| ... | @@ -44,6 +44,7 @@ | ... | @@ -44,6 +44,7 @@ |
| 44 | <script setup> | 44 | <script setup> |
| 45 | import { useRoute } from "vue-router"; | 45 | import { useRoute } from "vue-router"; |
| 46 | import dayjs from "dayjs"; | 46 | import dayjs from "dayjs"; |
| 47 | +import Cookies from 'js-cookie'; | ||
| 47 | 48 | ||
| 48 | const $route = useRoute(); | 49 | const $route = useRoute(); |
| 49 | const props = defineProps({ | 50 | const props = defineProps({ |
| ... | @@ -69,6 +70,19 @@ const onTap = () => { | ... | @@ -69,6 +70,19 @@ const onTap = () => { |
| 69 | const onConfirm = ({ selectedValues, selectedOptions }) => { | 70 | const onConfirm = ({ selectedValues, selectedOptions }) => { |
| 70 | props.item.value = selectedValues.join("-"); | 71 | props.item.value = selectedValues.join("-"); |
| 71 | showPicker.value = false; | 72 | showPicker.value = false; |
| 73 | + // 适配cookie保存未完成表单 | ||
| 74 | + const currentValue = selectedValues.join("-"); | ||
| 75 | + const existingCookie = Cookies.get($route.query.code); | ||
| 76 | + | ||
| 77 | + if (existingCookie) { | ||
| 78 | + // 如果Cookie存在,更新它 | ||
| 79 | + let obj = JSON.parse(existingCookie); | ||
| 80 | + obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 81 | + Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 82 | + } else { | ||
| 83 | + // 如果Cookie不存在,新增它 | ||
| 84 | + Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 85 | + } | ||
| 72 | }; | 86 | }; |
| 73 | 87 | ||
| 74 | const columns_type = ref([]); | 88 | const columns_type = ref([]); | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-08 15:02:45 | 2 | * @Date: 2022-09-08 15:02:45 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-08-09 11:40:31 | 4 | + * @LastEditTime: 2024-11-21 09:40:49 |
| 5 | * @FilePath: /data-table/src/components/DateTimePickerField/index.vue | 5 | * @FilePath: /data-table/src/components/DateTimePickerField/index.vue |
| 6 | * @Description: 日期时间选择器 | 6 | * @Description: 日期时间选择器 |
| 7 | --> | 7 | --> |
| ... | @@ -41,6 +41,7 @@ | ... | @@ -41,6 +41,7 @@ |
| 41 | import { useRoute } from "vue-router"; | 41 | import { useRoute } from "vue-router"; |
| 42 | import { showToast } from "vant"; | 42 | import { showToast } from "vant"; |
| 43 | import dayjs from "dayjs"; | 43 | import dayjs from "dayjs"; |
| 44 | +import Cookies from 'js-cookie'; | ||
| 44 | 45 | ||
| 45 | const $route = useRoute(); | 46 | const $route = useRoute(); |
| 46 | const props = defineProps({ | 47 | const props = defineProps({ |
| ... | @@ -71,6 +72,19 @@ const onConfirm = () => { | ... | @@ -71,6 +72,19 @@ const onConfirm = () => { |
| 71 | props.item.value = `${currentDate.value.join("-")}`; | 72 | props.item.value = `${currentDate.value.join("-")}`; |
| 72 | } | 73 | } |
| 73 | showPicker.value = false; | 74 | showPicker.value = false; |
| 75 | + // 适配cookie保存未完成表单 | ||
| 76 | + const currentValue = props.item.value; | ||
| 77 | + const existingCookie = Cookies.get($route.query.code); | ||
| 78 | + | ||
| 79 | + if (existingCookie) { | ||
| 80 | + // 如果Cookie存在,更新它 | ||
| 81 | + let obj = JSON.parse(existingCookie); | ||
| 82 | + obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 83 | + Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 84 | + } else { | ||
| 85 | + // 如果Cookie不存在,新增它 | ||
| 86 | + Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 87 | + } | ||
| 74 | }; | 88 | }; |
| 75 | const onCancel = () => { | 89 | const onCancel = () => { |
| 76 | showPicker.value = false; | 90 | showPicker.value = false; | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-14 14:44:30 | 2 | * @Date: 2022-09-14 14:44:30 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-11-21 09:32:58 | 4 | + * @LastEditTime: 2024-11-21 09:43:32 |
| 5 | * @FilePath: /data-table/src/components/NumberField/index.vue | 5 | * @FilePath: /data-table/src/components/NumberField/index.vue |
| 6 | * @Description: 数字输入框 | 6 | * @Description: 数字输入框 |
| 7 | --> | 7 | --> |
| ... | @@ -27,7 +27,6 @@ | ... | @@ -27,7 +27,6 @@ |
| 27 | readonly | 27 | readonly |
| 28 | @touchstart.stop="showKeyboard($event)" | 28 | @touchstart.stop="showKeyboard($event)" |
| 29 | :border="false" | 29 | :border="false" |
| 30 | - @blur="onBlur(item)" | ||
| 31 | > | 30 | > |
| 32 | </van-field> | 31 | </van-field> |
| 33 | <van-number-keyboard | 32 | <van-number-keyboard |
| ... | @@ -156,6 +155,19 @@ const blurKeyboard = () => { | ... | @@ -156,6 +155,19 @@ const blurKeyboard = () => { |
| 156 | document.getElementById("app").style.paddingBottom = "0"; | 155 | document.getElementById("app").style.paddingBottom = "0"; |
| 157 | // 还原border颜色 | 156 | // 还原border颜色 |
| 158 | content.css("border-color", "#eaeaea"); | 157 | content.css("border-color", "#eaeaea"); |
| 158 | + // 适配cookie保存未完成表单 | ||
| 159 | + const currentValue = props.item.value; | ||
| 160 | + const existingCookie = Cookies.get($route.query.code); | ||
| 161 | + | ||
| 162 | + if (existingCookie) { | ||
| 163 | + // 如果Cookie存在,更新它 | ||
| 164 | + let obj = JSON.parse(existingCookie); | ||
| 165 | + obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 166 | + Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 167 | + } else { | ||
| 168 | + // 如果Cookie不存在,新增它 | ||
| 169 | + Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 170 | + } | ||
| 159 | }; | 171 | }; |
| 160 | 172 | ||
| 161 | const showDecimal = ref(false); | 173 | const showDecimal = ref(false); |
| ... | @@ -196,22 +208,6 @@ const rules = [{ validator, message: validatorMessage }]; | ... | @@ -196,22 +208,6 @@ const rules = [{ validator, message: validatorMessage }]; |
| 196 | 208 | ||
| 197 | const onInput = (value) => {}; | 209 | const onInput = (value) => {}; |
| 198 | const onDelete = () => {}; | 210 | const onDelete = () => {}; |
| 199 | - | ||
| 200 | -// 适配cookie保存未完成表单 | ||
| 201 | -const onBlur = (item) => { | ||
| 202 | - const currentValue = v.value; | ||
| 203 | - const existingCookie = Cookies.get($route.query.code); | ||
| 204 | - | ||
| 205 | - if (existingCookie) { | ||
| 206 | - // 如果Cookie存在,更新它 | ||
| 207 | - let obj = JSON.parse(existingCookie); | ||
| 208 | - obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 209 | - Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 210 | - } else { | ||
| 211 | - // 如果Cookie不存在,新增它 | ||
| 212 | - Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 213 | - } | ||
| 214 | -} | ||
| 215 | </script> | 211 | </script> |
| 216 | 212 | ||
| 217 | <style lang="less" scoped> | 213 | <style lang="less" scoped> | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-31 11:45:30 | 2 | * @Date: 2022-08-31 11:45:30 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-08-09 11:49:07 | 4 | + * @LastEditTime: 2024-11-21 09:45:58 |
| 5 | * @FilePath: /data-table/src/components/TimePickerField/index.vue | 5 | * @FilePath: /data-table/src/components/TimePickerField/index.vue |
| 6 | * @Description: 时间选择组件 | 6 | * @Description: 时间选择组件 |
| 7 | --> | 7 | --> |
| ... | @@ -33,6 +33,7 @@ | ... | @@ -33,6 +33,7 @@ |
| 33 | <script setup> | 33 | <script setup> |
| 34 | import { useRoute } from "vue-router"; | 34 | import { useRoute } from "vue-router"; |
| 35 | import dayjs from "dayjs"; | 35 | import dayjs from "dayjs"; |
| 36 | +import Cookies from 'js-cookie'; | ||
| 36 | 37 | ||
| 37 | const $route = useRoute(); | 38 | const $route = useRoute(); |
| 38 | const props = defineProps({ | 39 | const props = defineProps({ |
| ... | @@ -58,6 +59,19 @@ const onTap = () => { | ... | @@ -58,6 +59,19 @@ const onTap = () => { |
| 58 | const onConfirm = ({ selectedValues, selectedOptions }) => { | 59 | const onConfirm = ({ selectedValues, selectedOptions }) => { |
| 59 | props.item.value = selectedValues.join(":"); | 60 | props.item.value = selectedValues.join(":"); |
| 60 | showPicker.value = false; | 61 | showPicker.value = false; |
| 62 | + // 适配cookie保存未完成表单 | ||
| 63 | + const currentValue = props.item.value; | ||
| 64 | + const existingCookie = Cookies.get($route.query.code); | ||
| 65 | + | ||
| 66 | + if (existingCookie) { | ||
| 67 | + // 如果Cookie存在,更新它 | ||
| 68 | + let obj = JSON.parse(existingCookie); | ||
| 69 | + obj[props.item.key] = currentValue; // 替换掉旧值 | ||
| 70 | + Cookies.set($route.query.code, JSON.stringify(obj)); | ||
| 71 | + } else { | ||
| 72 | + // 如果Cookie不存在,新增它 | ||
| 73 | + Cookies.set($route.query.code, JSON.stringify({ [props.item.key]: currentValue })); | ||
| 74 | + } | ||
| 61 | }; | 75 | }; |
| 62 | 76 | ||
| 63 | const columns_type = ref([]); | 77 | const columns_type = ref([]); | ... | ... |
-
Please register or login to post a comment