Browse Source

fix(address、datepicker): issue 问题修改:#1708、#1731 (#1745)

* fix: 修复 ImagePreview 在Taro编译成H5后报错的问题

* fix: 地址关闭时, Close 事件触发两次问题解决

* feat: 组件DatePicker 添加双向绑定
yangxiaolu1993 3 years ago
parent
commit
edddb36f9a

+ 1 - 1
src/packages/__VUE/address/doc.md

@@ -2,7 +2,7 @@
 
 ### 介绍
 
-按需加载请加载对应依赖组件 Icon Popup Elevator
+请加载对应依赖组件 Icon Popup Elevator
 
 ### 安装
 

+ 3 - 1
src/packages/__VUE/address/index.vue

@@ -460,6 +460,7 @@ export default create({
 
     // 关闭
     const close = () => {
+      console.log('关闭', closeWay.value, showPopup.value);
       const resCopy = Object.assign(
         {
           addressIdStr: '',
@@ -530,8 +531,9 @@ export default create({
     watch(
       () => showPopup.value,
       (value) => {
+        console.log('监听 showpopup', showPopup.value);
         if (value == false) {
-          close();
+          // close();
         } else {
           initCustomSelected();
         }

+ 1 - 0
src/packages/__VUE/datepicker/demo.vue

@@ -1,6 +1,7 @@
 <template>
   <div class="demo">
     <nut-cell-group :title="translate('basic')">
+      {{ currentDate }}
       <nut-cell :title="translate('showChinese')" :desc="desc1" @click="show = true"></nut-cell>
     </nut-cell-group>
 

+ 18 - 4
src/packages/__VUE/datepicker/index.vue

@@ -101,7 +101,7 @@ export default create({
     },
     filter: Function as PropType<import('./type').Filter>
   },
-  emits: ['click', 'update:visible', 'change', 'confirm', 'update:moduleValue'],
+  emits: ['click', 'update:visible', 'change', 'confirm', 'update:modelValue'],
 
   setup(props, { emit }) {
     const state = reactive({
@@ -249,11 +249,11 @@ export default create({
           formatDate.push(item);
         });
         if (props.type == 'month-day' && formatDate.length < 3) {
-          formatDate.unshift(new Date(props.modelValue || props.minDate || props.maxDate).getFullYear());
+          formatDate.unshift(new Date(state.currentDate || props.minDate || props.maxDate).getFullYear());
         }
 
         if (props.type == 'year-month' && formatDate.length < 3) {
-          formatDate.push(new Date(props.modelValue || props.minDate || props.maxDate).getDate());
+          formatDate.push(new Date(state.currentDate || props.minDate || props.maxDate).getDate());
         }
 
         const year = Number(formatDate[0]);
@@ -340,7 +340,21 @@ export default create({
     watch(
       () => props.modelValue,
       (value) => {
-        state.currentDate = formatValue(value);
+        const newValues = formatValue(value);
+        const isSameValue = JSON.stringify(newValues) === JSON.stringify(state.currentDate);
+        if (!isSameValue) {
+          state.currentDate = newValues;
+        }
+      }
+    );
+
+    watch(
+      () => state.currentDate,
+      (newValues) => {
+        const isSameValue = JSON.stringify(newValues) === JSON.stringify(props.modelValue);
+        if (!isSameValue) {
+          emit('update:modelValue', newValues);
+        }
       }
     );