Browse Source

feat: 地址组件替换icon

yangxiaolu3 3 years ago
parent
commit
375fcb15cd

+ 8 - 4
src/packages/__VUE/address/demo.vue

@@ -69,10 +69,13 @@
       @close="close3"
       :is-show-custom-address="false"
       @selected="selected"
-      :default-icon="defaultIcon"
-      :selected-icon="selectedIcon"
-      :close-btn-icon="closeBtnIcon"
     >
+      <template #unselectedIcon>
+        <Heart1 style="margin-right: 8px"></Heart1>
+      </template>
+      <template #icon>
+        <HeartFill style="margin-right: 8px" color="#f00"></HeartFill>
+      </template>
       <template #bottom>
         <div class="nut-address-custom-buttom">
           <div class="btn">自定义按钮</div>
@@ -91,7 +94,6 @@
       :city="city"
       :country="country"
       :town="town"
-      :back-btn-icon="backBtnIcon"
       @change="(cal) => onChange(cal, 'other')"
       @close="close4"
       @selected="selected"
@@ -106,6 +108,7 @@ import { createComponent } from '@/packages/utils/create';
 import { onMounted, reactive, ref, toRefs } from 'vue';
 import { useTranslate } from '@/sites/assets/util/useTranslate';
 const { createDemo, translate } = createComponent('address');
+import { HeartFill, Heart1, Close } from '@nutui/icons-vue';
 
 const initTranslate = () =>
   useTranslate({
@@ -165,6 +168,7 @@ interface AddressResult extends AddressList {
 }
 export default createDemo({
   props: {},
+  components: { HeartFill, Heart1, Close },
   setup() {
     initTranslate();
     const address = reactive({

+ 53 - 49
src/packages/__VUE/address/doc.en-US.md

@@ -2,7 +2,7 @@
 
 ### Intro
 
-Load on demand Load the  Icon、Popup、Elevator dependent component
+Load on demand Load the Popup、Elevator dependent component
 
 ### Install
 
@@ -327,22 +327,27 @@ If you want to select a province, you need to set the region ID in the order of
       @close="close"
       :is-show-custom-address="false"
       @selected="selected3"
-      :default-icon="defaultIcon"
-      :selected-icon="selectedIcon"
-      :close-btn-icon="closeBtnIcon"
-  ></nut-address>
+  >
+    <template #unselectedIcon>
+      <Heart1 style="margin-right:8px"></Heart1>
+    </template>
+    <template #icon>
+      <HeartFill style="margin-right:8px" color="#f00"></HeartFill>
+    </template>
+    <template #bottom>
+        <div class="nut-address-custom-buttom">
+          <div class="btn">自定义按钮</div>
+        </div>
+    </template>
+  </nut-address>
 </template>
 <script>
   import { ref,reactive,toRefs } from 'vue';
+  import { HeartFill, Heart1} from '@nutui/icons-vue';
   export default {
+    components:{HeartFill, Heart1 },
     setup() {
         const showPopupCustomImg = ref(false);
-        const icon = reactive({
-          selectedIcon: 'heart-fill',
-          defaultIcon: 'heart1',
-          closeBtnIcon: 'close',
-          backBtnIcon: 'left'
-        });
         const existAddress = ref([
           {
             id: 1,
@@ -418,7 +423,6 @@ If you want to select a province, you need to set the region ID in the order of
       :city="city"
       :country="country"
       :town="town"
-      :back-btn-icon="backBtnIcon"
       @close="close"
       @selected="selected"
       custom-and-exist-title="Choose Other Address"
@@ -528,60 +532,60 @@ If you want to select a province, you need to set the region ID in the order of
 # API
 
 | Attribute            | Description               | Type   | Default  |
-|----- | ----- | ----- | ----- 
-| v-model:visible | Whether to open address | String | ''
-| type | Choose type: exist/custom/custom2  | String | 'custom'
-| province | Province data| Array | []
-| city | City data | Array | []
-| country | Country data | Array | []
-| town | Town dta | Array | []
-| height | Popup height | String、Number | '200px'
-| exist-address | Exist address list data | Array | []
-| default-icon | Exist address default icon | String | ''
-| selected-icon | Exist address selected icon | String | ''
-| close-btn-icon | Custom close button icon | string | -
-| back-btn-icon | Custom back button icon | String | -
-| is-show-custom-address | Whether to change custom address | Boolean | true
-| custom-address-title  | Custom address title | String | 'Select Region'
-| exist-address-title|  Exist address title | String | 'Delivery To'
-| custom-and-exist-title| Custom address and existing address switch button copywriting | String | 'Choose Another Address'
-| columns-placeholder | Columns placeholder text | String|Array | 'Select'
-| lock-scroll   | Whether the background is locked   | Boolean        | `true`       
+|----- | ----- | ----- | ----- |
+| v-model:visible | Whether to open address | String | ''|
+| type | Choose type: exist/custom/custom2  | String | 'custom'|
+| province | Province data| Array | []|
+| city | City data | Array | []|
+| country | Country data | Array | []|
+| town | Town dta | Array | []|
+| height | Popup height | String、Number | '200px'|
+| exist-address | Exist address list data | Array | []|
+| is-show-custom-address | Whether to change custom address | Boolean | true|
+| custom-address-title  | Custom address title | String | 'Select Region'|
+| exist-address-title|  Exist address title | String | 'Delivery To'|
+| custom-and-exist-title| Custom address and existing address switch button copywriting | String | 'Choose Another Address'|
+| columns-placeholder | Columns placeholder text | String|Array | 'Select'|
+| lock-scroll   | Whether the background is locked   | Boolean        | `true`       |
 
 
 ## Event
 | Attribute            | Description               | Arguments   |
-|----- | ----- | ----- 
-| change |  Emitted when to selected custom address |  reference onChange
-| selected |  Emitted when to selected exist address  | reference selected
-| close |  Emitted when to close  | reference close
-| close-mask | Emitted when to close mask | {closeWay:'mask'/'cross'}
-| switch-module | Click to select another address or custom address to select the upper left corner of the return button triggered | {type:'exist'/'custom'/'custom2'}
+|----- | ----- | ----- |
+| change |  Emitted when to selected custom address |  reference onChange |
+| selected |  Emitted when to selected exist address  | reference selected |
+| close |  Emitted when to close  | reference close |
+| close-mask | Emitted when to close mask | {closeWay:'mask'/'cross'} |
+| switch-module | Click to select another address or custom address to select the upper left corner of the return button  triggered | {type:'exist'/'custom'/'custom2'} |
 
 
 ## change 
 | Attribute            | Description               | Options   |
-|----- | ----- | ----- 
-| custom | The administrative region currently clicked  |  province / city / country / town
-| next | The next level of the administrative region currently clicked | province / city / country / town
-| value | The value of the currently clicked administrative region | {}
+|----- | ----- | ----- |
+| custom | The administrative region currently clicked  |  province / city / country / town|
+| next | The next level of the administrative region currently clicked | province / city / country / town|
+| value | The value of the currently clicked administrative region | {}|
 
 ## selected 
 | Attribute            | Description               | Options   |
-|----- | ----- | ----- 
-| First Option(prevExistAdd) |  Select the previously selected address |  {}
-| Second Option(nowExistAdd) |  Currently selected address |  {}
-| Third Option(arr) |  After selecting the existing address list |  {}
+|----- | ----- | ----- |
+| First Option(prevExistAdd) |  Select the previously selected address |  {}|
+| Second Option(nowExistAdd) |  Currently selected address |  {}|
+| Third Option(arr) |  After selecting the existing address list |  {}|
 
 ## close 
 | Attribute            | Description               | Options   |
-|----- | ----- | ----- 
-| type | Selected Type  |  exist/custom/custom2
-| data | Selected Data | {} 
+|----- | ----- | ----- |
+| type | Selected Type  |  exist/custom/custom2|
+| data | Selected Data | {} |
 
 
 ## Slot
 | Attribute | Description | 
 |----- | ----- |  
-| bottom `3.1.23` | Bottom slot |  
+| bottom | Bottom slot |  
+| icon | Selected icon slot |  
+| unselectedIcon | Unselected icon slot |  
+| closeIcon | Close icon slot |  
+| backIcon | Change icon slot |  
     

+ 52 - 58
src/packages/__VUE/address/doc.md

@@ -2,7 +2,7 @@
 
 ### 介绍
 
-请加载对应依赖组件 Icon Popup Elevator
+请加载对应依赖组件 Popup Elevator
 
 ### 安装
 
@@ -77,7 +77,6 @@ app.use(Elevator);
           }
         };
         const close = val => {
-          console.log(val);
           text.value = val.data.addressStr;
         };
 
@@ -150,7 +149,6 @@ app.use(Elevator);
           }
         };
         const close = val => {
-          console.log(val);
           text.value = val.data.addressStr;
           value.value = [val.data.province.id, val.data.city.id, val.data.country.id];
         };
@@ -222,7 +220,6 @@ app.use(Elevator);
           }
         };
         const close = val => {
-          console.log(val);
           text.value = val.data.addressStr;
         };
 
@@ -328,10 +325,13 @@ app.use(Elevator);
       @close="close"
       :is-show-custom-address="false"
       @selected="selected3"
-      :default-icon="defaultIcon"
-      :selected-icon="selectedIcon"
-      :close-btn-icon="closeBtnIcon"
   >
+    <template #unselectedIcon>
+      <Heart1 style="margin-right:8px"></Heart1>
+    </template>
+    <template #icon>
+      <HeartFill style="margin-right:8px" color="#f00"></HeartFill>
+    </template>
     <template #bottom>
         <div class="nut-address-custom-buttom">
           <div class="btn">自定义按钮</div>
@@ -341,15 +341,11 @@ app.use(Elevator);
 </template>
 <script>
   import { ref,reactive,toRefs } from 'vue';
+  import { HeartFill, Heart1} from '@nutui/icons-vue';
   export default {
+    components:{HeartFill, Heart1 },
     setup() {
         const showPopupCustomImg = ref(false);
-        const icon = reactive({
-          selectedIcon: 'heart-fill',
-          defaultIcon: 'heart1',
-          closeBtnIcon: 'close',
-          backBtnIcon: 'left'
-        });
         const existAddress = ref([
           {
             id: 1,
@@ -406,7 +402,7 @@ app.use(Elevator);
           console.log(nowExistAdd);
         };
 
-        return { showPopupCustomImg, existAddress, text, showCustomImg, close, selected, ...toRefs(icon) };
+        return { showPopupCustomImg, existAddress, text, showCustomImg, close, selected };
     }
   }
 </script>
@@ -444,7 +440,6 @@ app.use(Elevator);
       :city="city"
       :country="country"
       :town="town"
-      :back-btn-icon="backBtnIcon"
       @close="close"
       @selected="selected"
       custom-and-exist-title="选择其他地址"
@@ -554,27 +549,22 @@ app.use(Elevator);
 ## API
 ### Props
 
-| 字段 | 说明 | 类型 | 默认值
-|----- | ----- | ----- | ----- 
-| v-model:visible | 是否打开地址选择 | String | ''
-| type | 地址选择类型 exist/custom/custom2  | String | 'custom'
-| province | 省,每个省的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | []
-| city | 市,每个市的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | []
-| country | 县,每个县的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | []
-| town | 乡/镇,每个乡/镇的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | []
-| height | 弹层中内容容器的高度,仅在type="custom2"时有效 | String、Number | '200px'
-| exist-address | 已存在地址列表,每个地址对象中,必传值provinceName、cityName、countyName、townName、addressDetail、selectedAddress(字段解释见下) | Array | []
-| default-icon | 已有地址列表默认图标,type=‘exist’ 时生效 | String | ''
-| selected-icon | 已有地址列表选中图标,type=‘exist’ 时生效 | String | ''
-| close-btn-icon | 自定义关闭弹框按钮图标 | string | -
-| back-btn-icon | 自定义地址与已有地址切换时,自定义返回的按钮图标 | String | -
-| is-show-custom-address | 是否可以切换自定义地址选择,type=‘exist’ 时生效 | Boolean | true
-| custom-address-title  | 自定义地址选择文案,type='custom' 时生效 | String | '请选择所在地区'
-| exist-address-title| 已有地址文案 ,type=‘exist’ 时生效| String | '配送至'
-| custom-and-exist-title| 自定义地址与已有地址切换按钮文案 ,type=‘exist’ 时生效| String | '选择其他地址'
-| columns-placeholder | 列提示文字 | String|Array | '请选择'
-| lock-scroll  | 背景是否锁定      | Boolean        | `true`       
-
+| 字段 | 说明 | 类型 | 默认值 |
+|----- | ----- | ----- | ----- |
+| v-model:visible | 是否打开地址选择 | String | '' |
+| type | 地址选择类型 exist/custom/custom2  | String | 'custom' |
+| province | 省,每个省的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | [] |
+| city | 市,每个市的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | [] |
+| country | 县,每个县的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | [] |
+| town | 乡/镇,每个乡/镇的对象中,必须有 name 字段,如果类型选择 custom2,必须指定 title 字段为首字母 | Array | [] |
+| height | 弹层中内容容器的高度,仅在type="custom2"时有效 | String、Number | '200px' |
+| exist-address | 已存在地址列表,每个地址对象中,必传值provinceName、cityName、countyName、townName、addressDetail、selectedAddress(字段解释见下) | Array | [] |
+| is-show-custom-address | 是否可以切换自定义地址选择,type=‘exist’ 时生效 | Boolean | true |
+| custom-address-title  | 自定义地址选择文案,type='custom' 时生效 | String | '请选择所在地区' |
+| exist-address-title| 已有地址文案 ,type=‘exist’ 时生效| String | '配送至' |
+| custom-and-exist-title| 自定义地址与已有地址切换按钮文案 ,type=‘exist’ 时生效| String | '选择其他地址' |
+| columns-placeholder | 列提示文字 | String|Array | '请选择' |
+| lock-scroll  | 背景是否锁定      | Boolean        | `true`  |
 
   * provinceName 省的名字
   * cityName 市的名字
@@ -584,36 +574,40 @@ app.use(Elevator);
   * selectedAddress 字段用于判断当前地址列表的选中项。
 
 ### Events
-| 字段 | 说明 | 回调参数 
-|----- | ----- | ----- 
-| change | 自定义选择地址时,选择地区时触发 |  参考 onChange
-| selected | 选择已有地址列表时触发 | 参考 selected
-| close | 地址选择弹框关闭时触发 | 参考 close
-| close-mask |点击遮罩层或点击右上角叉号关闭时触发 | {closeWay:'mask'/'cross'}
-| switch-module | 点击‘选择其他地址’或自定义地址选择左上角返回按钮触发 | {type:'exist'/'custom'/'custom2'}
+| 字段 | 说明 | 回调参数  |
+|----- | ----- | ----- |
+| change | 自定义选择地址时,选择地区时触发 |  参考 onChange |
+| selected | 选择已有地址列表时触发 | 参考 selected |
+| close | 地址选择弹框关闭时触发 | 参考 close |
+| close-mask |点击遮罩层或点击右上角叉号关闭时触发 | {closeWay:'mask'/'cross'} |
+| switch-module | 点击‘选择其他地址’或自定义地址选择左上角返回按钮触发 | {type:'exist'/'custom'/'custom2'} |
 
 
 ### change 回调参数
-| 参数 | 说明 | 可能值 
-|----- | ----- | ----- 
-| custom | 当前点击的行政区域  |  province(省) / city(市) / country(县) / town(乡)
-| next | 当前点击的行政区域的下一级 | province(省) / city(市) / country(县) / town(乡)
-| value | 当前点击的行政区域的值(返回传入的值) | {}
+| 参数 | 说明 | 可选值 |
+|----- | ----- | ----- |
+| custom | 当前点击的行政区域  |  province(省) / city(市) / country(县) / town(乡) |
+| next | 当前点击的行政区域的下一级 | province(省) / city(市) / country(县) / town(乡) |
+| value | 当前点击的行政区域的值(返回传入的值) | {} |
 
 ### selected 回调参数
-| 参数 | 说明 | 可能值 
-|----- | ----- | ----- 
-| 第一个参数(prevExistAdd) |  选择前选中的地址 |  {}
-| 第二个参数(nowExistAdd) |  当前选中的地址 |  {}
-| 第三个参数(arr) |  选择完之后的已有地址列表(selectedAddress 值发生改变) |  {}
+| 参数 | 说明 | 可能值 |
+|----- | ----- | ----- |
+| 第一个参数(prevExistAdd) |  选择前选中的地址 |  {} |
+| 第二个参数(nowExistAdd) |  当前选中的地址 |  {} |
+| 第三个参数(arr) |  选择完之后的已有地址列表(selectedAddress 值发生改变) |  {} |
 
 ### close 回调参数
-| 参数 | 说明 | 可能值 
-|----- | ----- | ----- 
-| type | 地址选择类型 exist/custom/custom2  |  exist/custom/custom2
-| data | 选择地址的值,custom 时,addressStr 为选择的地址组合 | {} 
+| 参数 | 说明 | 可能值 |
+|----- | ----- | ----- |
+| type | 地址选择类型 exist/custom/custom2  |  exist/custom/custom2 |
+| data | 选择地址的值,custom 时,addressStr 为选择的地址组合 | {}  |
 
 ### Slots
 | 字段 | 说明 | 
 |----- | ----- |  
-| bottom `3.1.23` | 可自定义底部 |  
+| bottom | 可自定义底部 |  
+| icon | 自定义选中项的图标 |  
+| unselectedIcon | 未选中地址时的图标 |  
+| closeIcon | 关闭弹层的图标 |  
+| backIcon | 自定义地址与已有地址切换时返回的图标 |  

+ 3 - 3
src/packages/__VUE/address/index.scss

@@ -46,13 +46,11 @@
     display: flex;
     justify-content: space-between;
     align-items: center;
-    margin-top: 24px;
-    margin-bottom: 17px;
+    height: 68px;
     padding: 0 20px;
     text-align: center;
     font-weight: bold;
     color: #333;
-    line-height: 20px;
     &__title {
       display: block;
       color: $address-header-title-color;
@@ -147,6 +145,8 @@
             font-weight: bold;
           }
           > div {
+            display: flex;
+            align-items: center;
             margin: 10px 0;
           }
         }

+ 20 - 61
src/packages/__VUE/address/index.vue

@@ -12,12 +12,9 @@
     <view class="nut-address">
       <view class="nut-address__header">
         <view class="nut-address__header-back" @click="switchModule">
-          <nut-icon
-            v-bind="$attrs"
-            :name="backBtnIcon"
-            color="#cccccc"
-            v-show="type == 'exist' && privateType == 'custom' && backBtnIcon"
-          ></nut-icon>
+          <slot name="backIcon">
+            <Left v-show="type == 'exist' && privateType == 'custom'"></Left>
+          </slot>
         </view>
 
         <view class="nut-address__header__title">
@@ -29,7 +26,9 @@
         </view>
 
         <view class="nut-address__header-close" @click="handClose('cross')">
-          <nut-icon v-bind="$attrs" v-if="closeBtnIcon" :name="closeBtnIcon" color="#cccccc" size="18px"></nut-icon>
+          <slot name="closeIcon">
+            <Close color="#cccccc" size="18px"></Close>
+          </slot>
         </view>
       </view>
 
@@ -60,12 +59,9 @@
               @click="nextAreaList(item)"
             >
               <div>
-                <component
-                  :is="renderIcon(selectedIcon)"
-                  v-bind="$attrs"
-                  v-if="selectedRegion[tabIndex]?.id == item.id"
-                ></component>
-                {{ item.name }}
+                <slot name="icon" v-if="selectedRegion[tabIndex]?.id == item.id">
+                  <Check class="nut-address-select-icon" width="13px"></Check> </slot
+                >{{ item.name }}
               </div>
             </li>
           </ul>
@@ -90,10 +86,14 @@
               :key="index"
               @click="selectedExist(item)"
             >
-              <component
-                :is="renderIcon(item.selectedAddress ? selectedIcon : defaultIcon)"
-                v-bind="$attrs"
-              ></component>
+              <slot name="unselectedIcon" v-if="!item.selectedAddress">
+                <Location2 class="nut-address-select-icon" width="13px"></Location2>
+              </slot>
+
+              <slot name="icon" v-if="item.selectedAddress">
+                <Check class="nut-address-select-icon" width="13px"></Check>
+              </slot>
+
               <div class="nut-address__exist-item-info">
                 <div class="nut-address__exist-item-info-name" v-if="item.name">{{ item.name }}</div>
                 <div class="nut-address__exist-item-info-phone" v-if="item.phone">{{ item.phone }}</div>
@@ -123,25 +123,11 @@ import { reactive, ref, toRefs, watch, nextTick, computed, Ref, h, PropType } fr
 import { createComponent } from '@/packages/utils/create';
 import { RegionData, CustomRegionData, existRegionData } from './type';
 import { popupProps } from '../popup/props';
-import Icon from '../icon/index.vue';
-import Popup from '../popup/index.vue';
-import Elevator from '../elevator/index.vue';
 const { componentName, create, translate } = createComponent('address');
+import { Location, Location2, Check, Close, Left } from '@nutui/icons-vue';
 
-interface AddressList {
-  id?: string | number;
-  provinceName: string;
-  cityName: string;
-  countyName: string;
-  townName: string;
-  addressDetail: string;
-  selectedAddress: boolean;
-}
 export default create({
-  components: {
-    [Popup.name]: Popup,
-    [Elevator.name]: Elevator
-  },
+  components: { Location, Location2, Check, Close, Left },
   inheritAttrs: false,
   props: {
     ...popupProps,
@@ -189,22 +175,6 @@ export default create({
       type: String,
       default: ''
     },
-    defaultIcon: {
-      type: String,
-      default: 'location2'
-    },
-    selectedIcon: {
-      type: String,
-      default: 'Check'
-    },
-    closeBtnIcon: {
-      type: String,
-      default: 'circle-close'
-    },
-    backBtnIcon: {
-      type: String,
-      default: 'left'
-    },
     height: {
       type: [String, Number],
       default: '200px'
@@ -237,15 +207,6 @@ export default create({
       }
     });
 
-    const renderIcon = (n: string) => {
-      return h(Icon, {
-        class: `${componentName}-select-icon`,
-        type: 'self',
-        size: '13px',
-        name: n
-      });
-    };
-
     const transformData = (data: RegionData[]) => {
       if (!Array.isArray(data)) throw new TypeError('params muse be array.');
 
@@ -399,7 +360,6 @@ export default create({
 
     // 手动关闭 点击叉号(cross),或者蒙层(mask)
     const handClose = (type = 'self') => {
-      if (!props.closeBtnIcon) return;
       closeWay.value = type == 'cross' ? 'cross' : 'self';
       showPopup.value = false;
     };
@@ -497,8 +457,7 @@ export default create({
       ...toRefs(props),
       translate,
       regionList,
-      transformData,
-      renderIcon
+      transformData
     };
   }
 });