mali-applet-ui 1.1.80 → 1.1.81

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/config/index.js CHANGED
@@ -6,4 +6,4 @@ function config (options) {
6
6
  return globalStore
7
7
  }
8
8
 
9
- export default config
9
+ export default config
package/config/json.js ADDED
@@ -0,0 +1,30 @@
1
+ import globalStore from './store'
2
+ import XEUtils from 'xe-utils'
3
+
4
+ let provincesPromise
5
+
6
+ export function getProvincesJSON () {
7
+ if (provincesPromise) {
8
+ return provincesPromise
9
+ }
10
+ if (globalStore.provincesPicker && globalStore.provincesPicker.jsonUrl) {
11
+ provincesPromise = new Promise((resolve) => {
12
+ uni.request({
13
+ url: globalStore.provincesPicker.jsonUrl,
14
+ method: 'GET',
15
+ dataType: 'json',
16
+ success (res) {
17
+ resolve(XEUtils.isArray(res.data) ? res.data : [])
18
+ },
19
+ fail (e) {
20
+ provincesPromise = null
21
+ resolve([])
22
+ }
23
+ })
24
+ })
25
+ } else {
26
+ provincesPromise = Promise.resolve([])
27
+ console.error('缺少全局配置:provincesPicker.jsonUrl')
28
+ }
29
+ return provincesPromise
30
+ }
@@ -30,36 +30,7 @@
30
30
  </template>
31
31
 
32
32
  <script>
33
- import provinceCityRegionData from '../ml-provinces-picker/provincesData'
34
-
35
- const codeMpas = {}
36
- const provinceData = []
37
- const provinceCityData = []
38
- provinceCityRegionData.forEach(provinceItem => {
39
- codeMpas[provinceItem.code] = provinceItem
40
- provinceData.push({
41
- code: provinceItem.code,
42
- name: provinceItem.name
43
- })
44
- provinceCityData.push({
45
- code: provinceItem.code,
46
- name: provinceItem.name,
47
- children: provinceItem.children
48
- ? provinceItem.children.map(cityItem => {
49
- codeMpas[cityItem.code] = cityItem
50
- if (cityItem.children) {
51
- cityItem.children.forEach(regionItem => {
52
- codeMpas[regionItem.code] = regionItem
53
- })
54
- }
55
- return {
56
- code: cityItem.code,
57
- name: cityItem.name
58
- }
59
- })
60
- : []
61
- })
62
- })
33
+ import { getProvincesJSON } from '../../../config/json'
63
34
 
64
35
  export default {
65
36
  name: 'MlProvinceCityPicker',
@@ -83,6 +54,11 @@ export default {
83
54
  },
84
55
  data () {
85
56
  return {
57
+ codeMpas: [],
58
+ provinceData: [],
59
+ provinceCityData: [],
60
+ provinceCityRegionData: [],
61
+
86
62
  showPopup: false,
87
63
  showPicker: false,
88
64
  selectVals: [0]
@@ -116,9 +92,9 @@ export default {
116
92
  },
117
93
  provinceList () {
118
94
  if (this.isAll) {
119
- return [{ name: '全部', code: '', _all: true }].concat(provinceCityData)
95
+ return [{ name: '全部', code: '', _all: true }].concat(this.provinceCityData)
120
96
  }
121
- return provinceCityData
97
+ return this.provinceCityData
122
98
  },
123
99
  selectProvinceValue () {
124
100
  return this.selectProvinceItem ? this.selectProvinceItem[this.optValueField] : ''
@@ -141,6 +117,46 @@ export default {
141
117
  this.selectVals[1] = 0
142
118
  }
143
119
  },
120
+ created () {
121
+ getProvincesJSON().then((list) => {
122
+ const codeMpas = {}
123
+ const provinceData = []
124
+ const provinceCityData = []
125
+ const provinceCityRegionData = []
126
+
127
+ list.forEach(provinceItem => {
128
+ codeMpas[provinceItem.code] = provinceItem
129
+ provinceData.push({
130
+ code: provinceItem.code,
131
+ name: provinceItem.name
132
+ })
133
+ provinceCityData.push({
134
+ code: provinceItem.code,
135
+ name: provinceItem.name,
136
+ children: provinceItem.children
137
+ ? provinceItem.children.map(cityItem => {
138
+ codeMpas[cityItem.code] = cityItem
139
+ if (cityItem.children) {
140
+ cityItem.children.forEach(regionItem => {
141
+ codeMpas[regionItem.code] = regionItem
142
+ })
143
+ }
144
+ return {
145
+ code: cityItem.code,
146
+ name: cityItem.name
147
+ }
148
+ })
149
+ : []
150
+ })
151
+ provinceCityRegionData.push(provinceItem)
152
+ })
153
+
154
+ this.codeMpas = codeMpas
155
+ this.provinceData = provinceData
156
+ this.provinceCityData = provinceCityData
157
+ this.provinceCityRegionData = provinceCityRegionData
158
+ })
159
+ },
144
160
  methods: {
145
161
  closePopup () {
146
162
  this.showPopup = false
@@ -17,36 +17,7 @@
17
17
 
18
18
  <script>
19
19
  import XEUtils from 'xe-utils'
20
- import provinceCityRegionData from './provincesData'
21
-
22
- const codeMpas = {}
23
- const provinceData = []
24
- const provinceCityData = []
25
- provinceCityRegionData.forEach(provinceItem => {
26
- codeMpas[provinceItem.code] = provinceItem
27
- provinceData.push({
28
- code: provinceItem.code,
29
- name: provinceItem.name
30
- })
31
- provinceCityData.push({
32
- code: provinceItem.code,
33
- name: provinceItem.name,
34
- children: provinceItem.children
35
- ? provinceItem.children.map(cityItem => {
36
- codeMpas[cityItem.code] = cityItem
37
- if (cityItem.children) {
38
- cityItem.children.forEach(regionItem => {
39
- codeMpas[regionItem.code] = regionItem
40
- })
41
- }
42
- return {
43
- code: cityItem.code,
44
- name: cityItem.name
45
- }
46
- })
47
- : []
48
- })
49
- })
20
+ import { getProvincesJSON } from '../../../config/json'
50
21
 
51
22
  export default {
52
23
  name: 'MlProvincesPicker',
@@ -87,6 +58,11 @@ export default {
87
58
  },
88
59
  data () {
89
60
  return {
61
+ codeMpas: [],
62
+ provinceData: [],
63
+ provinceCityData: [],
64
+ provinceCityRegionData: [],
65
+
90
66
  selectVals: []
91
67
  }
92
68
  },
@@ -109,7 +85,7 @@ export default {
109
85
  selectLabel () {
110
86
  if (this.optValueField === 'code') {
111
87
  return this.selectVals.map(val => {
112
- const item = codeMpas[val]
88
+ const item = this.codeMpas[val]
113
89
  return item ? item[this.optLabelField] : val
114
90
  }).join('/')
115
91
  }
@@ -117,12 +93,12 @@ export default {
117
93
  },
118
94
  optList () {
119
95
  if (this.showRegion) {
120
- return provinceCityRegionData
96
+ return this.provinceCityRegionData
121
97
  }
122
98
  if (this.showCity) {
123
- return provinceCityData
99
+ return this.provinceCityData
124
100
  }
125
- return provinceData
101
+ return this.provinceData
126
102
  }
127
103
  },
128
104
  watch: {
@@ -134,6 +110,45 @@ export default {
134
110
  }
135
111
  },
136
112
  created () {
113
+ getProvincesJSON().then((list) => {
114
+ const codeMpas = {}
115
+ const provinceData = []
116
+ const provinceCityData = []
117
+ const provinceCityRegionData = []
118
+
119
+ list.forEach(provinceItem => {
120
+ codeMpas[provinceItem.code] = provinceItem
121
+ provinceData.push({
122
+ code: provinceItem.code,
123
+ name: provinceItem.name
124
+ })
125
+ provinceCityData.push({
126
+ code: provinceItem.code,
127
+ name: provinceItem.name,
128
+ children: provinceItem.children
129
+ ? provinceItem.children.map(cityItem => {
130
+ codeMpas[cityItem.code] = cityItem
131
+ if (cityItem.children) {
132
+ cityItem.children.forEach(regionItem => {
133
+ codeMpas[regionItem.code] = regionItem
134
+ })
135
+ }
136
+ return {
137
+ code: cityItem.code,
138
+ name: cityItem.name
139
+ }
140
+ })
141
+ : []
142
+ })
143
+ provinceCityRegionData.push(provinceItem)
144
+ })
145
+
146
+ this.codeMpas = codeMpas
147
+ this.provinceData = provinceData
148
+ this.provinceCityData = provinceCityData
149
+ this.provinceCityRegionData = provinceCityRegionData
150
+ })
151
+
137
152
  this.selectVals = this.handleMode(this.value)
138
153
  },
139
154
  methods: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mali-applet-ui",
3
- "version": "1.1.80",
3
+ "version": "1.1.81",
4
4
  "description": "码里UI-小程序组件库(vue2)",
5
5
  "files": [
6
6
  "lib",
package/types/index.d.ts CHANGED
@@ -20,6 +20,9 @@ export interface ConfigOptions {
20
20
  pager?: any
21
21
  notData?: any
22
22
  listSelectUserPage?: any
23
+ provincesPicker?: {
24
+ jsonUrl?: string
25
+ }
23
26
  [key: string]: any
24
27
  }
25
28