Browse Source

docs: address

suzigang 4 years ago
parent
commit
e4565b3ab7

+ 59 - 25
src/packages/address/demo.vue

@@ -16,7 +16,7 @@
       :town="town"
       :town="town"
       @change="cal => onChange(cal, 'normal')"
       @change="cal => onChange(cal, 'normal')"
       @close="close1"
       @close="close1"
-      customAddressTitle="请选择所在地区"
+      custom-address-title="请选择所在地区"
     ></nut-address>
     ></nut-address>
 
 
     <h2>选择已有地址</h2>
     <h2>选择已有地址</h2>
@@ -30,12 +30,12 @@
     <nut-address
     <nut-address
       v-model:show="exist"
       v-model:show="exist"
       type="exist"
       type="exist"
-      :existAddress="existAddress"
+      :exist-address="existAddress"
       @change="cal => onChange(cal, 'exist')"
       @change="cal => onChange(cal, 'exist')"
       @close="close2"
       @close="close2"
-      :isShowCustomAddress="false"
+      :is-show-custom-address="false"
       @selected="selected"
       @selected="selected"
-      existAddressTitle="配送至"
+      exist-address-title="配送至"
     ></nut-address>
     ></nut-address>
 
 
     <h2>自定义图标</h2>
     <h2>自定义图标</h2>
@@ -49,14 +49,14 @@
     <nut-address
     <nut-address
       v-model:show="customImg"
       v-model:show="customImg"
       type="exist"
       type="exist"
-      :existAddress="existAddress"
+      :exist-address="existAddress"
       @change="cal => onChange(cal, 'customImg')"
       @change="cal => onChange(cal, 'customImg')"
       @close="close3"
       @close="close3"
-      :isShowCustomAddress="false"
+      :is-show-custom-address="false"
       @selected="selected"
       @selected="selected"
-      :defaultIcon="defaultIcon"
-      :selectedIcon="selectedIcon"
-      :closeBtnIcon="closeBtnIcon"
+      :default-icon="defaultIcon"
+      :selected-icon="selectedIcon"
+      :close-btn-icon="closeBtnIcon"
     ></nut-address>
     ></nut-address>
 
 
     <h2>自定义地址与已有地址切换</h2>
     <h2>自定义地址与已有地址切换</h2>
@@ -70,18 +70,18 @@
     <nut-address
     <nut-address
       v-model:show="other"
       v-model:show="other"
       type="exist"
       type="exist"
-      :existAddress="existAddress"
+      :exist-address="existAddress"
       :province="province"
       :province="province"
       :city="city"
       :city="city"
       :country="country"
       :country="country"
       :town="town"
       :town="town"
-      :backBtnIcon="backBtnIcon"
+      :back-btn-icon="backBtnIcon"
       @change="cal => onChange(cal, 'other')"
       @change="cal => onChange(cal, 'other')"
       @close="close4"
       @close="close4"
       @selected="selected"
       @selected="selected"
-      customAndExistTitle="选择其他地址"
-      @switchModule="switchModule"
-      @closeMask="closeMask"
+      custom-and-exist-title="选择其他地址"
+      @switch-module="switchModule"
+      @close-mask="closeMask"
     ></nut-address>
     ></nut-address>
   </div>
   </div>
 </template>
 </template>
@@ -90,6 +90,36 @@
 import { createComponent } from '@/utils/create';
 import { createComponent } from '@/utils/create';
 import { reactive, ref, toRefs } from 'vue';
 import { reactive, ref, toRefs } from 'vue';
 const { createDemo } = createComponent('address');
 const { createDemo } = createComponent('address');
+interface CalBack {
+  next: string;
+  value: string;
+  custom: string;
+}
+interface RegionData {
+  name: string;
+  [key: string]: any;
+}
+interface CalResult {
+  type: string;
+  data: AddressResult;
+}
+interface AddressList {
+  id?: string | number;
+  provinceName: string;
+  cityName: string;
+  countyName: string;
+  townName: string;
+  addressDetail: string;
+  selectedAddress: boolean;
+}
+interface AddressResult extends AddressList {
+  addressIdStr: string;
+  addressStr: string;
+  province: RegionData[];
+  city: RegionData[];
+  country: RegionData[];
+  town: RegionData[];
+}
 export default createDemo({
 export default createDemo({
   props: {},
   props: {},
   setup() {
   setup() {
@@ -178,13 +208,13 @@ export default createDemo({
       showPopup.normal = !showPopup.normal;
       showPopup.normal = !showPopup.normal;
     };
     };
 
 
-    const onChange = (cal, tag) => {
-      const name = address[cal.next];
+    const onChange = (cal: CalBack, tag: string) => {
+      const name = (address as any)[cal.next];
       if (name.length < 1) {
       if (name.length < 1) {
-        showPopup[tag] = false;
+        (showPopup as any)[tag] = false;
       }
       }
     };
     };
-    const close1 = val => {
+    const close1 = (val: CalResult) => {
       console.log(val);
       console.log(val);
       text.one = val.data.addressStr;
       text.one = val.data.addressStr;
     };
     };
@@ -193,7 +223,7 @@ export default createDemo({
       showPopup.exist = true;
       showPopup.exist = true;
     };
     };
 
 
-    const close2 = val => {
+    const close2 = (val: CalResult) => {
       console.log(val);
       console.log(val);
       if (val.type == 'exist') {
       if (val.type == 'exist') {
         const {
         const {
@@ -209,7 +239,11 @@ export default createDemo({
         text.two = val.data.addressStr;
         text.two = val.data.addressStr;
       }
       }
     };
     };
-    const selected = (prevExistAdd, nowExistAdd, arr) => {
+    const selected = (
+      prevExistAdd: AddressList,
+      nowExistAdd: RegionData,
+      arr: AddressList[]
+    ) => {
       console.log(prevExistAdd);
       console.log(prevExistAdd);
       console.log(nowExistAdd);
       console.log(nowExistAdd);
     };
     };
@@ -221,7 +255,7 @@ export default createDemo({
       showPopup.customImg = true;
       showPopup.customImg = true;
     };
     };
 
 
-    const close3 = val => {
+    const close3 = (val: CalResult) => {
       console.log(val);
       console.log(val);
       if (val.type == 'exist') {
       if (val.type == 'exist') {
         const {
         const {
@@ -238,7 +272,7 @@ export default createDemo({
       }
       }
     };
     };
 
 
-    const close4 = val => {
+    const close4 = (val: CalResult) => {
       console.log(val);
       console.log(val);
       if (val.type == 'exist') {
       if (val.type == 'exist') {
         const {
         const {
@@ -255,15 +289,15 @@ export default createDemo({
       }
       }
     };
     };
 
 
-    const switchModule = cal => {
-      if (cal.type == 'custom') {
+    const switchModule = (val: CalResult) => {
+      if (val.type == 'custom') {
         console.log('点击了“选择其他地址”按钮');
         console.log('点击了“选择其他地址”按钮');
       } else {
       } else {
         console.log('点击了自定义地址左上角的返回按钮');
         console.log('点击了自定义地址左上角的返回按钮');
       }
       }
     };
     };
 
 
-    const closeMask = val => {
+    const closeMask = (val: CalResult) => {
       console.log('关闭弹层', val);
       console.log('关闭弹层', val);
     };
     };
 
 

+ 13 - 13
src/packages/address/doc.md

@@ -361,20 +361,20 @@ setup() {
 | 字段 | 说明 | 类型 | 默认值
 | 字段 | 说明 | 类型 | 默认值
 |----- | ----- | ----- | ----- 
 |----- | ----- | ----- | ----- 
 | v-model:show | 是否打开地址选择 | String | ''
 | v-model:show | 是否打开地址选择 | String | ''
-| type | 地址选择类型 exist/custom | String | custom
+| type | 地址选择类型 exist/custom | String | 'custom'
 | province | 省,每个省的对象中,必须有 name 字段 | Array | []
 | province | 省,每个省的对象中,必须有 name 字段 | Array | []
 | city | 市,每个市的对象中,必须有 name 字段 | Array | []
 | city | 市,每个市的对象中,必须有 name 字段 | Array | []
 | country | 县,每个县的对象中,必须有 name 字段 | Array | []
 | country | 县,每个县的对象中,必须有 name 字段 | Array | []
 | town | 乡/镇,每个乡/镇的对象中,必须有 name 字段 | Array | []
 | town | 乡/镇,每个乡/镇的对象中,必须有 name 字段 | Array | []
-| existAddress | 已存在地址列表,每个地址对象中,必传值provinceName、cityName、countyName、townName、addressDetail、selectedAddress(字段解释见下) | Array | []
-| defaultIcon | 已有地址列表默认图标,type=‘exist’ 时生效 | string | ''
-| selectedIcon | 已有地址列表选中图标,type=‘exist’ 时生效 | string | ''
-| closeBtnIcon | 自定义关闭弹框按钮图标 | string | -
-| backBtnIcon | 自定义地址与已有地址切换时,自定义返回的按钮图标 | string | -
-| isShowCustomAddress | 是否可以切换自定义地址选择,type=‘exist’ 时生效 | Boolean | true
-| customAddressTitle  | 自定义地址选择文案,type='custom' 时生效 | string | '请选择所在地区'
-| existAddressTitle| 已有地址文案 ,type=‘exist’ 时生效| string | '配送至'
-| customAndExistTitle| 自定义地址与已有地址切换按钮文案 ,type=‘exist’ 时生效| string | '选择其他地址'
+| 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 | '选择其他地址'
 
 
 
 
   * provinceName 省的名字
   * provinceName 省的名字
@@ -387,11 +387,11 @@ setup() {
 ## Event
 ## Event
 | 字段 | 说明 | 回调参数 
 | 字段 | 说明 | 回调参数 
 |----- | ----- | ----- 
 |----- | ----- | ----- 
-| onChange | 自定义选择地址时,选择地区时触发 |  参考 onChange
+| on-change | 自定义选择地址时,选择地区时触发 |  参考 onChange
 | selected | 选择已有地址列表时触发 | 参考 selected
 | selected | 选择已有地址列表时触发 | 参考 selected
 | close | 地址选择弹框关闭时触发 | 参考 close
 | close | 地址选择弹框关闭时触发 | 参考 close
-| closeMask | 点击遮罩层或点击右上角叉号关闭时触发 | {closeWay:'mask'/'cross'}
-| switchModule | 点击‘选择其他地址’或自定义地址选择左上角返回按钮触发 | {type:'exist'/'custom'}
+| close-mask |点击遮罩层或点击右上角叉号关闭时触发 | {closeWay:'mask'/'cross'}
+| switch-module | 点击‘选择其他地址’或自定义地址选择左上角返回按钮触发 | {type:'exist'/'custom'}
 
 
 
 
 ## onChange 回调参数
 ## onChange 回调参数

+ 5 - 9
src/packages/address/index.scss

@@ -50,11 +50,7 @@
         margin-top: 5px;
         margin-top: 5px;
         width: 26px;
         width: 26px;
         height: 3px;
         height: 3px;
-        background: linear-gradient(
-          90deg,
-          $primary-color 0%,
-          $primary-color-end 100%
-        );
+        background: $address-region-tab-line;
       }
       }
     }
     }
 
 
@@ -69,7 +65,7 @@
           display: flex;
           display: flex;
           align-items: center;
           align-items: center;
           margin-bottom: 20px;
           margin-bottom: 20px;
-          font-size: 12px;
+          font-size: $font-size-1;
           color: #333;
           color: #333;
           &.active {
           &.active {
             font-weight: bold;
             font-weight: bold;
@@ -97,9 +93,9 @@
           display: flex;
           display: flex;
           align-items: center;
           align-items: center;
           margin-bottom: 20px;
           margin-bottom: 20px;
-          font-size: 12px;
+          font-size: $font-size-1;
           line-height: 14px;
           line-height: 14px;
-          color: rgba(51, 51, 51, 1);
+          color: #333;
           &.active {
           &.active {
             font-weight: bold;
             font-weight: bold;
           }
           }
@@ -128,7 +124,7 @@
         background: $button-primary-background-color;
         background: $button-primary-background-color;
         border-radius: 21px;
         border-radius: 21px;
         font-size: 15px;
         font-size: 15px;
-        color: rgba(255, 255, 255, 1);
+        color: $white;
       }
       }
     }
     }
   }
   }

+ 55 - 40
src/packages/address/index.vue

@@ -12,8 +12,9 @@
           class="arrow-back"
           class="arrow-back"
           @click="switchModule"
           @click="switchModule"
           v-if="showModule == 'custom' && type == 'exist' && backBtnIcon"
           v-if="showModule == 'custom' && type == 'exist' && backBtnIcon"
-          ><nut-icon :name="backBtnIcon" color="#CCCCCC"></nut-icon
-        ></view-block>
+        >
+          <nut-icon :name="backBtnIcon" color="#CCCCCC"></nut-icon>
+        </view-block>
         <view-block class="arrow-back" v-else></view-block>
         <view-block class="arrow-back" v-else></view-block>
 
 
         <view-block v-if="showModule == 'custom'">{{
         <view-block v-if="showModule == 'custom'">{{
@@ -23,14 +24,14 @@
           existAddressTitle
           existAddressTitle
         }}</view-block>
         }}</view-block>
 
 
-        <view-block class="arrow-close" @click="handClose('cross')"
-          ><nut-icon
+        <view-block class="arrow-close" @click="handClose('cross')">
+          <nut-icon
             v-if="closeBtnIcon"
             v-if="closeBtnIcon"
             :name="closeBtnIcon"
             :name="closeBtnIcon"
             color="#CCCCCC"
             color="#CCCCCC"
             size="18px"
             size="18px"
-          ></nut-icon
-        ></view-block>
+          ></nut-icon>
+        </view-block>
       </view-block>
       </view-block>
 
 
       <!-- 请选择 -->
       <!-- 请选择 -->
@@ -43,8 +44,9 @@
             :key="index"
             :key="index"
             :ref="key"
             :ref="key"
             @click="changeRegionTab(item, key, index)"
             @click="changeRegionTab(item, key, index)"
-            ><view>{{ getTabName(item, index) }}</view></view-block
           >
           >
+            <view>{{ getTabName(item, index) }}</view>
+          </view-block>
 
 
           <view-block class="region-tab-line" ref="regionLine"></view-block>
           <view-block class="region-tab-line" ref="regionLine"></view-block>
         </view-block>
         </view-block>
@@ -120,6 +122,27 @@ import { reactive, ref, toRefs, watch, nextTick } from 'vue';
 import { createComponent } from '@/utils/create';
 import { createComponent } from '@/utils/create';
 const { componentName, create } = createComponent('address');
 const { componentName, create } = createComponent('address');
 import { TweenMax } from 'gsap';
 import { TweenMax } from 'gsap';
+interface RegionData {
+  name: string;
+  [key: string]: any;
+}
+interface Region {
+  province: RegionData[];
+  city: RegionData[];
+  country: RegionData[];
+  town: RegionData[];
+  [key: string]: any;
+}
+
+interface AddressList {
+  id?: string | number;
+  provinceName: string;
+  cityName: string;
+  countyName: string;
+  townName: string;
+  addressDetail: string;
+  selectedAddress: boolean;
+}
 export default create({
 export default create({
   props: {
   props: {
     show: {
     show: {
@@ -197,13 +220,7 @@ export default create({
   ],
   ],
 
 
   setup(props, { emit }) {
   setup(props, { emit }) {
-    console.log('componentName', componentName);
-
     const regionLine = ref<null | HTMLElement>(null);
     const regionLine = ref<null | HTMLElement>(null);
-    // const tabItemprovince = ref<null | HTMLElement>(null);
-    // const tabItemcity = ref<null | HTMLElement>(null);
-    // const tabItemcountry = ref<null | HTMLElement>(null);
-    // const tabItemtown = ref<null | HTMLElement>(null);
 
 
     const tabItemRef = reactive({
     const tabItemRef = reactive({
       province: ref<null | HTMLElement>(null),
       province: ref<null | HTMLElement>(null),
@@ -225,10 +242,10 @@ export default create({
     });
     });
 
 
     const selectedRegion = reactive({
     const selectedRegion = reactive({
-      province: {},
-      city: {},
-      country: {},
-      town: {}
+      province: {} as RegionData,
+      city: {} as RegionData,
+      country: {} as RegionData,
+      town: {} as RegionData
     }); //已选择的 省、市、县、镇
     }); //已选择的 省、市、县、镇
 
 
     let selectedExistAddress = reactive({}); // 当前选择的地址
     let selectedExistAddress = reactive({}); // 当前选择的地址
@@ -236,7 +253,7 @@ export default create({
     const closeWay = ref('self');
     const closeWay = ref('self');
 
 
     //获取已选地区列表名称
     //获取已选地区列表名称
-    const getTabName = (item, index) => {
+    const getTabName = (item: RegionData, index: number) => {
       if (item.name) return item.name;
       if (item.name) return item.name;
 
 
       if (tabIndex.value < index) {
       if (tabIndex.value < index) {
@@ -259,7 +276,7 @@ export default create({
     };
     };
     // 移动下面的红线
     // 移动下面的红线
     const lineAnimation = () => {
     const lineAnimation = () => {
-      const name = tabItemRef[tabName.value[tabIndex.value]];
+      const name = (tabItemRef as any)[tabName.value[tabIndex.value]];
       nextTick(() => {
       nextTick(() => {
         if (name) {
         if (name) {
           const distance = name.offsetLeft;
           const distance = name.offsetLeft;
@@ -268,7 +285,7 @@ export default create({
       });
       });
     };
     };
     // 切换下一级列表
     // 切换下一级列表
-    const nextAreaList = item => {
+    const nextAreaList = (item: RegionData | string) => {
       // onchange 接收的参数
       // onchange 接收的参数
       const calBack = {
       const calBack = {
         next: '',
         next: '',
@@ -276,10 +293,10 @@ export default create({
         custom: tabName.value[tabIndex.value]
         custom: tabName.value[tabIndex.value]
       };
       };
 
 
-      selectedRegion[tabName.value[tabIndex.value]] = item;
+      (selectedRegion as any)[tabName.value[tabIndex.value]] = item;
 
 
       for (let i = tabIndex.value; i < tabIndex.value - 1; i++) {
       for (let i = tabIndex.value; i < tabIndex.value - 1; i++) {
-        selectedRegion[tabName.value[i + 1]] = {};
+        (selectedRegion as any)[tabName.value[i + 1]] = {};
       }
       }
 
 
       if (tabIndex.value < 3) {
       if (tabIndex.value < 3) {
@@ -289,28 +306,28 @@ export default create({
 
 
         // 切换下一个
         // 切换下一个
         calBack.next = tabName.value[tabIndex.value];
         calBack.next = tabName.value[tabIndex.value];
-        calBack.value = item;
+        calBack.value = item as string;
         emit('change', calBack);
         emit('change', calBack);
       } else {
       } else {
         handClose();
         handClose();
       }
       }
     };
     };
     //切换地区Tab
     //切换地区Tab
-    const changeRegionTab = (item, key, index) => {
+    const changeRegionTab = (item: RegionData, key: number, index: number) => {
       tabIndex.value = index;
       tabIndex.value = index;
       lineAnimation();
       lineAnimation();
     };
     };
 
 
     // 选择现有地址
     // 选择现有地址
-    const selectedExist = item => {
-      const copyExistAdd = props.existAddress as [];
+    const selectedExist = (item: RegionData) => {
+      const copyExistAdd = props.existAddress as AddressList[];
       let prevExistAdd = {};
       let prevExistAdd = {};
 
 
       copyExistAdd.forEach((list, index) => {
       copyExistAdd.forEach((list, index) => {
-        if (list && (list as any).selectedAddress) {
+        if (list && (list as AddressList).selectedAddress) {
           prevExistAdd = list;
           prevExistAdd = list;
         }
         }
-        (list as any).selectedAddress = false;
+        (list as AddressList).selectedAddress = false;
       });
       });
 
 
       item.selectedAddress = true;
       item.selectedAddress = true;
@@ -324,7 +341,7 @@ export default create({
     // 初始化
     // 初始化
     const initAddress = () => {
     const initAddress = () => {
       for (let i = 0; i < tabName.value.length; i++) {
       for (let i = 0; i < tabName.value.length; i++) {
-        selectedRegion[tabName.value[i]] = {};
+        (selectedRegion as any)[tabName.value[i]] = {};
       }
       }
       tabIndex.value = 0;
       tabIndex.value = 0;
       lineAnimation();
       lineAnimation();
@@ -332,8 +349,6 @@ export default create({
 
 
     // 关闭
     // 关闭
     const close = () => {
     const close = () => {
-      console.log('关闭');
-
       const resCopy = Object.assign(
       const resCopy = Object.assign(
         {
         {
           addressIdStr: '',
           addressIdStr: '',
@@ -351,16 +366,16 @@ export default create({
         const { province, city, country, town } = resCopy;
         const { province, city, country, town } = resCopy;
 
 
         resCopy.addressIdStr = [
         resCopy.addressIdStr = [
-          (province as any).id || 0,
-          (city as any).id || 0,
-          (country as any).id || 0,
-          (town as any).id || 0
+          (province as RegionData).id || 0,
+          (city as RegionData).id || 0,
+          (country as RegionData).id || 0,
+          (town as RegionData).id || 0
         ].join('_');
         ].join('_');
         resCopy.addressStr = [
         resCopy.addressStr = [
-          (province as any).name,
-          (city as any).name,
-          (country as any).name,
-          (town as any).name
+          (province as RegionData).name,
+          (city as RegionData).name,
+          (country as RegionData).name,
+          (town as RegionData).name
         ].join('');
         ].join('');
         res.data = resCopy;
         res.data = resCopy;
       } else {
       } else {
@@ -437,7 +452,7 @@ export default create({
       value => {
       value => {
         //  existAddress.value = value;
         //  existAddress.value = value;
         value.forEach((item, index) => {
         value.forEach((item, index) => {
-          if ((item as any).selectedAddress) {
+          if ((item as AddressList).selectedAddress) {
             selectedExistAddress = item as {};
             selectedExistAddress = item as {};
           }
           }
         });
         });

+ 7 - 1
src/styles/variables.scss

@@ -226,7 +226,6 @@ $tabbar-active-color: $primary-color;
 $tabbar-border-color: #eee;
 $tabbar-border-color: #eee;
 
 
 //infiniteloading
 //infiniteloading
-
 $infinite-bottom-color: #c8c8c8;
 $infinite-bottom-color: #c8c8c8;
 
 
 //range
 //range
@@ -238,6 +237,13 @@ $rang-bar-bg-color: linear-gradient(
   $primary-color-end 100%
   $primary-color-end 100%
 );
 );
 
 
+//address
+$address-region-tab-line: linear-gradient(
+  90deg,
+  $primary-color 0%,
+  $primary-color-end 100%
+);
+
 view-block {
 view-block {
   display: block;
   display: block;
 }
 }