vue2-client 1.12.50 → 1.12.51

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": "vue2-client",
3
- "version": "1.12.50",
3
+ "version": "1.12.51",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --no-eslint",
@@ -15,7 +15,7 @@
15
15
  </div>
16
16
  <!-- 自定义标题 -->
17
17
  <template #title>
18
- <div class="custom-title" @click="clickFooter(card, 'cardclick', itemIndex)">
18
+ <div class="custom-title" @click="cardClick(card, 'cardclick', itemIndex)">
19
19
  <a-tooltip placement="top">
20
20
  <template #title>{{ card[config.id] }}</template>
21
21
  <div class="title-id" v-if="card[config.id]">{{ card[config.id] }}</div>
@@ -278,7 +278,7 @@ export default {
278
278
  three: '未获取到配置',
279
279
  four: '未获取到配置',
280
280
  five: '未获取到配置',
281
- six: 70
281
+ six: 70,
282
282
  }
283
283
  }
284
284
  // 测试数据初始化
@@ -307,28 +307,20 @@ export default {
307
307
  }
308
308
  return result
309
309
  },
310
- // 点击按钮
310
+ async cardClick (card, itemIndex) {
311
+ try {
312
+ // 等待 beforeSwitch 完全执行完成
313
+ const result = await this.beforeSwitch(card, 'beforeSwitch', itemIndex)
314
+ // 如果返回 undefined 说明没有监听器,或者返回 true 说明检查通过
315
+ if (result === undefined || result === true) {
316
+ await this.clickFooter(card, 'cardclick', itemIndex)
317
+ }
318
+ } catch (error) {
319
+ }
320
+ },
311
321
  // 点击按钮
312
322
  async clickFooter (data, eventName, index) {
313
323
  if (eventName === 'cardclick') {
314
- // 先触发 beforeSwitch 事件
315
- if (this.data && Array.isArray(this.data)) {
316
- for (const item of this.data) {
317
- if (item.isClicked) {
318
- // 使用 Promise 包装 beforeSwitch 事件
319
- await new Promise((resolve, reject) => {
320
- try {
321
- // 执行 beforeSwitch 事件
322
- this.$emit('cardEmit', item, 'beforeSwitch')
323
- resolve()
324
- } catch (error) {
325
- reject(error)
326
- }
327
- })
328
- }
329
- }
330
- }
331
- // 如果上面的代码块执行成功,才会执行下面的代码
332
324
  // 清除所有卡片的点击状态
333
325
  if (this.data && Array.isArray(this.data)) {
334
326
  this.data.forEach(item => {
@@ -342,6 +334,32 @@ export default {
342
334
  }
343
335
  this.$emit('cardEmit', data, eventName)
344
336
  },
337
+ async beforeSwitch (data, eventName, index) {
338
+ return new Promise((resolve) => {
339
+ // 检查是否有其他卡片已经被点击
340
+ const hasClickedCard = this.data.some(item => item.isClicked)
341
+ // 如果没有任何卡片被点击过,直接通过
342
+ if (!hasClickedCard) {
343
+ resolve(true)
344
+ return
345
+ }
346
+ // 检查是否有监听器
347
+ const hasListeners = this._events?.cardEmit?.length > 0
348
+
349
+ // 如果没有监听器,返回 undefined 表示继续执行
350
+ if (!hasListeners) {
351
+ resolve(undefined)
352
+ return
353
+ }
354
+ // 如果有监听器,执行事件检查
355
+ try {
356
+ this.$emit('cardEmit', data, eventName)
357
+ resolve(true)
358
+ } catch (error) {
359
+ resolve(false)
360
+ }
361
+ })
362
+ },
345
363
  // 获取数据
346
364
  loadData () {
347
365
  this.render = false