Prechádzať zdrojové kódy

fix: handle empty activity apply data

Developer 4 dní pred
rodič
commit
96a5833647

BIN
dist.zip


+ 12 - 12
src/views/modules/activity/info.vue

@@ -102,7 +102,7 @@ export default {
       provinceName: '',
       cityName: '',
       districtName: '',
-      activityInfo: null,
+      activityInfo: {},
       activityLimitCfg: {
         1: '爱心值',
         2: '专享券',
@@ -145,23 +145,23 @@ export default {
     getDetail (id) {
       this.$http.get('/core/activity/' + id).then(({ data: res }) => {
         if (res.code !== 0) return this.$message.error(res.msg)
-        this.activityInfo = res.data
-        this.getSSQ(res.data.provinceId, 'provinceName')
-        this.getSSQ(res.data.cityId, 'cityName')
-        this.getSSQ(res.data.districtId, 'districtName')
+        this.activityInfo = res.data || {}
+        this.getSSQ(this.activityInfo.provinceId, 'provinceName')
+        this.getSSQ(this.activityInfo.cityId, 'cityName')
+        this.getSSQ(this.activityInfo.districtId, 'districtName')
       })
     },
     getList () {
       this.loading = true
       this.$http.get('/core/activity/signup/getSignupList', { params: this.queryParams }).then(({ data: res }) => {
         if (res.code !== 0) return this.$message.error(res.msg)
-        this.dataList = res.data.list
-        this.dataList.forEach(d => {
-          d.contactPhoneJM = d.contactPhone.replace(/^(.{3})(?:\d+)(.{4})$/, '$1****$2')
-          d.idCardJM = d.idCard.replace(/^(\d{6})(\d{8})(\d{3}[\dX])$/i, '$1********$3')
-          d.age = this.getAge(d.idCard)
-        })
-        this.total = res.data.total
+        this.dataList = (res.data && res.data.list) || []
+        this.dataList.forEach(d => {
+          d.contactPhoneJM = d.contactPhone ? d.contactPhone.replace(/^(.{3})(?:\d+)(.{4})$/, '$1****$2') : ''
+          d.idCardJM = d.idCard ? d.idCard.replace(/^(\d{6})(\d{8})(\d{3}[\dX])$/i, '$1********$3') : ''
+          d.age = this.getAge(d.idCard)
+        })
+        this.total = (res.data && res.data.total) || 0
         this.loading = false
       })
     },

+ 14 - 0
tests/activity-apply-info-null-data.test.js

@@ -0,0 +1,14 @@
+import test from 'node:test'
+import assert from 'node:assert/strict'
+import fs from 'node:fs'
+import path from 'node:path'
+
+const infoFile = path.resolve('src/views/modules/activity/info.vue')
+
+test('活动报名信息页初始化和脱敏处理兼容空数据', () => {
+  const source = fs.readFileSync(infoFile, 'utf8')
+
+  assert.match(source, /activityInfo:\s*\{\}/)
+  assert.match(source, /d\.contactPhoneJM\s*=\s*d\.contactPhone\s*\?\s*d\.contactPhone\.replace/)
+  assert.match(source, /d\.idCardJM\s*=\s*d\.idCard\s*\?\s*d\.idCard\.replace/)
+})