haiwei-ui 1.2.9 → 1.3.1

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": "haiwei-ui",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "description": "HaiWei前端组件库",
5
5
  "author": "Eric",
6
6
  "license": "ISC",
@@ -104,12 +104,45 @@ export default {
104
104
  this.options = options
105
105
  this.loading = false
106
106
 
107
+ // 检查当前值是否在新加载的选项中
108
+ if (this.value_ && options.length > 0) {
109
+ const found = this.findOptionByValue(this.value_)
110
+ if (found) {
111
+ console.log('【nm-select】refresh后找到匹配选项:', found.label, '->', found.value)
112
+ } else {
113
+ console.warn('【nm-select】refresh后未找到匹配选项,当前值:', this.value_)
114
+ }
115
+ }
116
+
107
117
  if (this.checkedFirst && !this.hasInit && options.length > 0) {
108
118
  this.onChange(options[0].value)
109
119
  this.hasInit = true
110
120
  }
111
121
  })
112
122
  },
123
+ // 根据值查找选项
124
+ findOptionByValue(value) {
125
+ if (!value || !this.options.length) return null
126
+
127
+ if (this.multiple && Array.isArray(value)) {
128
+ // 多选模式,返回匹配的选项数组
129
+ return value.map(v => {
130
+ for (let i = 0; i < this.options.length; i++) {
131
+ const opt = this.options[i]
132
+ if (opt.value === v) return opt
133
+ }
134
+ return null
135
+ }).filter(opt => opt !== null)
136
+ } else {
137
+ // 单选模式
138
+ for (let i = 0; i < this.options.length; i++) {
139
+ const opt = this.options[i]
140
+ if (opt.value === value) return opt
141
+ }
142
+ return null
143
+ }
144
+ },
145
+
113
146
  onChange(val) {
114
147
  this.value_ = val
115
148
  this.$emit('input', this.value_)
@@ -154,8 +187,30 @@ export default {
154
187
  }
155
188
  },
156
189
  watch: {
157
- value() {
158
- this.value_ = this.value
190
+ value: {
191
+ immediate: true,
192
+ handler(newVal, oldVal) {
193
+ console.log('【nm-select】value 变化:', oldVal, '->', newVal)
194
+ this.value_ = newVal
195
+
196
+ // 如果新值不为空,检查新值是否在选项中
197
+ if (newVal) {
198
+ // 如果选项数据已加载,立即检查
199
+ if (this.options.length > 0) {
200
+ const found = this.findOptionByValue(newVal)
201
+ if (!found) {
202
+ console.warn('【nm-select】值', newVal, '不在当前选项列表中,尝试重新加载选项数据')
203
+ // 值不在当前选项中,重新加载选项数据
204
+ this.refresh()
205
+ } else {
206
+ console.log('【nm-select】找到匹配选项:', found.label, '->', found.value)
207
+ }
208
+ } else {
209
+ console.log('【nm-select】选项数据尚未加载,等待refresh后检查')
210
+ // 选项数据尚未加载,将在refresh方法中检查
211
+ }
212
+ }
213
+ }
159
214
  }
160
215
  },
161
216
  render(h) {
@@ -194,7 +194,7 @@ export default config => {
194
194
  if (t && t.accessToken) {
195
195
  config.headers.Authorization = 'Bearer ' + t.accessToken
196
196
  }
197
-
197
+
198
198
  // 开发环境下打印请求日志
199
199
  if (process.env.NODE_ENV === 'development') {
200
200
  console.group(`[API请求] ${config.method.toUpperCase()} ${config.url}`)
@@ -207,7 +207,7 @@ export default config => {
207
207
  })
208
208
  console.groupEnd()
209
209
  }
210
-
210
+
211
211
  return config
212
212
  },
213
213
  function(error) {
@@ -223,7 +223,7 @@ export default config => {
223
223
  axios.interceptors.response.use(
224
224
  response => {
225
225
  const { config } = response
226
-
226
+
227
227
  // 开发环境下打印响应成功日志
228
228
  if (process.env.NODE_ENV === 'development') {
229
229
  console.group(`[API响应] ${config.method.toUpperCase()} ${config.url}`)
@@ -235,7 +235,7 @@ export default config => {
235
235
  })
236
236
  console.groupEnd()
237
237
  }
238
-
238
+
239
239
  // 文件下载/预览
240
240
  if (config.responseType && config.responseType === 'blob') {
241
241
  return handleDownload(response)
@@ -261,7 +261,7 @@ export default config => {
261
261
  const url = error.config && error.config.url ? error.config.url : 'unknown'
262
262
  const status = error.response && error.response.status
263
263
  const responseData = error.response && error.response.data
264
-
264
+
265
265
  console.group(`[API错误] ${method} ${url}`)
266
266
  console.log('错误信息:', {
267
267
  状态码: status,
@@ -271,7 +271,7 @@ export default config => {
271
271
  })
272
272
  console.groupEnd()
273
273
  }
274
-
274
+
275
275
  let currentRoute = router.currentRoute
276
276
  let redirect = currentRoute.name !== 'login' ? currentRoute.fullPath : '/' // 跳转页面
277
277
  if (error && error.response) {