vue_zhongyou 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue_zhongyou",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -211,6 +211,7 @@
211
211
  <van-area
212
212
  :area-list="areaList"
213
213
  :columns-placeholder="addressPopup.columnsPlaceholder || ['请选择', '请选择', '请选择']"
214
+ v-model="addressPopup.value"
214
215
  @confirm="onAddressConfirm"
215
216
  @cancel="closeAddressPicker"
216
217
  />
@@ -293,7 +294,8 @@ const addressPopup = ref({
293
294
  visible: false,
294
295
  field: null,
295
296
  areaList: null,
296
- columnsPlaceholder: null
297
+ columnsPlaceholder: null,
298
+ value: ''
297
299
  })
298
300
 
299
301
  // 存储各个datetime字段的选择时间
@@ -322,7 +324,7 @@ const getDefaultValue = (type) => {
322
324
  if (type === 'dateRange') return ['', '']
323
325
  if (type === 'datetimeRange') return ['', '']
324
326
  if (type === 'datetime') return ''
325
- if (type === 'address') return { province: '', city: '', county: '', code: '' }
327
+ if (type === 'address') return ''
326
328
  return ''
327
329
  }
328
330
 
@@ -613,16 +615,48 @@ const getDateTimeRangeText = (field) => {
613
615
 
614
616
  // Address
615
617
  const openAddressPicker = (field) => {
616
- addressPopup.value = {
618
+ const config = {
617
619
  visible: true,
618
620
  field,
619
621
  areaList: areaList,
620
622
  columnsPlaceholder: field.columnsPlaceholder
621
623
  }
624
+
625
+ // 如果表单数据中已有code值,则设置默认选中项
626
+ const fieldValue = formData[field.field]
627
+ let code = ''
628
+
629
+ // 如果fieldValue是一个对象且包含code属性
630
+ if (fieldValue && typeof fieldValue === 'object' && fieldValue.code) {
631
+ code = fieldValue.code
632
+ }
633
+ // 如果fieldValue是一个字符串(直接是code值)
634
+ else if (fieldValue && typeof fieldValue === 'string') {
635
+ code = fieldValue
636
+ }
637
+
638
+ if (code) {
639
+ config.value = getCodeToAreaValue(code)
640
+ }
641
+
642
+ addressPopup.value = config
643
+ }
644
+
645
+ // 根据code获取地址选择器的默认值
646
+ const getCodeToAreaValue = (code) => {
647
+ if (!code) return ''
648
+
649
+ // 确保code是字符串且长度为6
650
+ const codeStr = String(code).padEnd(6, '0')
651
+
652
+ // 返回完整的6位code作为value
653
+ return codeStr
622
654
  }
623
655
 
624
656
  const closeAddressPicker = () => {
625
657
  addressPopup.value.visible = false
658
+ // 清除value值,以免影响下次打开
659
+ addressPopup.value.value = ''
626
660
  }
627
661
 
628
662
  const onAddressConfirm = ({ selectedOptions }) => {
@@ -632,13 +666,17 @@ const onAddressConfirm = ({ selectedOptions }) => {
632
666
  }
633
667
  console.log(selectedOptions);
634
668
 
635
- const [province, city, county] = selectedOptions
636
- updateFieldValue(addressPopup.value.field.field, {
637
- province: province?.text || '',
638
- city: city?.text || '',
639
- county: county?.text || '',
640
- code: county?.value || city?.value || province?.value || ''
641
- })
669
+ // 从数组中找出最后一项value值不为000000的值作为当前的code值返回
670
+ let code = '';
671
+ for (let i = selectedOptions.length - 1; i >= 0; i--) {
672
+ const option = selectedOptions[i];
673
+ if (option && option.value && option.value !== '000000') {
674
+ code = option.value;
675
+ break;
676
+ }
677
+ }
678
+
679
+ updateFieldValue(addressPopup.value.field.field, code)
642
680
 
643
681
  // 触发modelValue更新
644
682
  emit('update:modelValue', snapshot())
@@ -648,8 +686,38 @@ const onAddressConfirm = ({ selectedOptions }) => {
648
686
 
649
687
  const getAddressText = (field) => {
650
688
  const value = formData[field.field]
651
- if (!value) return ''
652
- const parts = [value.province, value.city, value.county].filter(Boolean)
689
+ // 如果value是一个对象且包含code属性
690
+ if (value && typeof value === 'object' && value.code) {
691
+ return getCodeToAddressText(value.code)
692
+ }
693
+
694
+ // 如果value是一个字符串(直接是code值)
695
+ if (value && typeof value === 'string') {
696
+ return getCodeToAddressText(value)
697
+ }
698
+
699
+ return ''
700
+ }
701
+
702
+ // 根据code获取地址文本
703
+ const getCodeToAddressText = (code) => {
704
+ if (!code) return ''
705
+
706
+ // 确保code是字符串且长度为6
707
+ const codeStr = String(code).padEnd(6, '0')
708
+
709
+ // 提取省、市、区县的code
710
+ const provinceCode = codeStr.substring(0, 2) + '0000'
711
+ const cityCode = codeStr.substring(0, 4) + '00'
712
+ const countyCode = codeStr
713
+
714
+ // 获取对应的文本
715
+ const province = areaList.province_list[provinceCode] || ''
716
+ const city = areaList.city_list[cityCode] || ''
717
+ const county = areaList.county_list[countyCode] || ''
718
+
719
+ // 过滤掉空值并拼接
720
+ const parts = [province, city, county].filter(Boolean)
653
721
  return parts.join('')
654
722
  }
655
723