From 84819d1bded641ad111a456e4e88a2810dea310f Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期四, 17 九月 2026 14:17:30 +0800
Subject: [PATCH] feat(投资): 新增市州月报解析引擎(Step1 地基)+ 回填用户口径确认

---
 traffic-audit-web/src/views/ReportExport.vue |  146 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 136 insertions(+), 10 deletions(-)

diff --git a/traffic-audit-web/src/views/ReportExport.vue b/traffic-audit-web/src/views/ReportExport.vue
index 2cbe51b..bf645b9 100644
--- a/traffic-audit-web/src/views/ReportExport.vue
+++ b/traffic-audit-web/src/views/ReportExport.vue
@@ -99,12 +99,14 @@
             </div>
           </el-alert>
         </div>
-        <el-dialog :title="'棰勮鏁版嵁 - ' + previewModule + '锛�' + previewPeriod + '锛�'" :visible.sync="previewVisible" width="760px">
+        <el-dialog :title="'棰勮鏁版嵁 - ' + previewModule + '锛�' + previewPeriod + '锛�'" :visible.sync="previewVisible" width="760px"
+                   top="5vh" custom-class="pv-dialog" v-dialog-drag>
           <div class="preview-body">
             <div v-for="it in previewItems" :key="it.key" class="preview-item">
               <div class="preview-head">
                 <span class="preview-name">{{ it.label }}</span>
-                <span class="preview-rows">鍏� {{ it.rowCount || 0 }} 琛�</span>
+                <span class="preview-rows" v-if="it.key === 'summaryWorkbook'">鎸囨爣 {{ (it.summary || []).length }} 椤�</span>
+                <span class="preview-rows" v-else>鍏� {{ it.rowCount || 0 }} 琛屾槑缁�</span>
               </div>
               <div class="preview-coverage">
                 <span class="cov-label">鏈堝害瑕嗙洊锛�</span>
@@ -112,7 +114,25 @@
                 <span v-if="!it.ready" class="cov-bad" style="margin-left:10px">{{ it.note }}</span>
                 <span v-if="it.ready && it.audited === false" class="cov-bad" style="margin-left:10px">鏈鏍�</span>
               </div>
-              <table class="preview-summary" v-if="it.summary && it.summary.length">
+              <table class="preview-summary wb-table" v-if="it.key === 'summaryWorkbook' && it.summary && it.summary.length">
+                <thead>
+                  <tr><th style="width:12%">鍒嗙被</th><th style="width:40%">鎸囨爣</th><th style="width:28%">鏁版嵁</th><th>鍚屾瘮</th></tr>
+                </thead>
+                <tbody>
+                  <template v-for="(sec, si) in wbRows(it.summary)">
+                    <tr v-for="(row, ri) in sec.rows" :key="si + '-' + ri">
+                      <td v-if="ri === 0" :rowspan="sec.rows.length" class="wb-sec">{{ sec.name }}</td>
+                      <td class="wb-label">{{ row.label }}</td>
+                      <td class="wb-value">{{ row.value === null ? '鈥�' : fmtVal(row.value) }}</td>
+                      <td class="wb-yoy" :class="{ 'yoy-empty': row.yoy === null }">{{ row.yoy === null ? '鈥�' : row.yoy }}</td>
+                    </tr>
+                  </template>
+                </tbody>
+              </table>
+              <div v-if="it.key === 'summaryWorkbook' && wbMissing(it.summary)" class="wb-note">
+                閮ㄥ垎鎸囨爣缂哄皯涓婂勾鍚屾湡锛坽{ wbPrevYear() }}锛夊熀鏈熸暟鎹紝鍚屾瘮鏆傛湭璁$畻
+              </div>
+              <table class="preview-summary" v-if="it.key !== 'summaryWorkbook' && it.summary && it.summary.length">
                 <tbody>
                   <tr v-for="(s, i) in it.summary" :key="i">
                     <td>{{ s.label }}</td>
@@ -370,7 +390,7 @@
           this.previewVisible = true
           this.loading = ''
         })
-        .catch(err => this.failWith(err))
+        .catch(err => this.failWith(err, '棰勮'))
     },
     fmtVal(v) {
       if (v === null || v === undefined || v === '') return '鈥�'
@@ -379,6 +399,65 @@
         return v.toFixed(4).replace(/\.?0+$/, '')
       }
       return String(v)
+    },
+    wbRows(summary) {
+      const get = (key) => {
+        const hit = (summary || []).find(x => x.label === key)
+        return hit && hit.value !== null && hit.value !== undefined && hit.value !== '' ? hit.value : null
+      }
+      const pct = (key) => {
+        const v = get(key)
+        return v === null ? null : this.fmtVal(v) + '%'
+      }
+      const mk = (defs) => defs.map(d => ({
+        label: d[0],
+        value: get(d[1]),
+        yoy: d[2] ? pct(d[2]) : null
+      }))
+      return [
+        {
+          name: '閬撹矾璐ц繍',
+          rows: mk([
+            ['褰撴湀璐ц繍閲�(涓囧惃)', '鍏ㄧ渷璐ц繍閲徛峰綋鏈�'],
+            ['褰撴湀璐х墿鍛ㄨ浆閲�(涓囧惃)', '鍏ㄧ渷璐х墿鍛ㄨ浆閲徛峰綋鏈�', '鍏ㄧ渷璐х墿鍛ㄨ浆閲徛峰綋鏈堝悓姣�'],
+            ['绱璐ц繍閲�(涓囧惃)', '鍏ㄧ渷璐ц繍閲徛风疮璁�'],
+            ['绱璐х墿鍛ㄨ浆閲�(涓囧惃鍏噷)', '鍏ㄧ渷璐х墿鍛ㄨ浆閲徛风疮璁�', '鍏ㄧ渷璐х墿鍛ㄨ浆閲徛风疮璁″悓姣�']
+          ])
+        },
+        {
+          name: '鍩庡競瀹㈣繍',
+          rows: mk([
+            ['褰撴湀鍩庡競瀹㈣繍閲�:', '鍩庡競瀹㈣繍閲徛峰綋鏈�'],
+            ['褰撴湀鍩庡競瀹㈣繍鍛ㄨ浆閲�', '鍩庡競瀹㈣繍鍛ㄨ浆閲徛峰綋鏈�'],
+            ['绱鍩庡競瀹㈣繍閲�:', '鍩庡競瀹㈣繍閲徛风疮璁�'],
+            ['绱鍩庡競瀹㈣繍鍛ㄨ浆閲�', '鍩庡競瀹㈣繍鍛ㄨ浆閲徛风疮璁�']
+          ])
+        },
+        {
+          name: '涓彛寰�',
+          rows: mk([
+            ['褰撴湀涓彛寰勫杩愰噺', '涓彛寰勫杩愰噺路褰撴湀'],
+            ['褰撴湀涓彛寰勫懆杞噺', '涓彛寰勫懆杞噺路褰撴湀'],
+            ['绱涓彛寰勫杩愰噺', '涓彛寰勫杩愰噺路绱'],
+            ['绱涓彛寰勫懆杞噺', '涓彛寰勫懆杞噺路绱']
+          ])
+        }
+      ]
+    },
+    wbMissing(summary) {
+      let total = 0
+      let have = 0
+      ;(summary || []).forEach(x => {
+        if (String(x.label).indexOf('鍚屾瘮') >= 0) return
+        total++
+        if (x.value !== null && x.value !== undefined && x.value !== '') have++
+      })
+      return total > 0 && have < total
+    },
+    wbPrevYear() {
+      const m = /^(\d{4})-(\d{2})$/.exec(this.previewPeriod || '')
+      if (!m) return '涓婂勾鍚屾湡'
+      return (Number(m[1]) - 1) + '-' + m[2]
     },
     coverageText(it) {
       const cov = it.monthCoverage || []
@@ -428,13 +507,45 @@
         })
         .catch(() => doExport())
     },
-    failWith(err) {
+    // 棰勮/瀵煎嚭澶辫触缁熶竴鎻愮ず锛氬尯鍒嗏�滆繛涓嶄笂鏈嶅姟鍣ㄢ�濅笌鈥滃悗绔繑鍥炵殑閿欒鍘熷洜鈥濄��
+    // 瀵煎嚭鎺ュ彛鐢� responseType: 'blob'锛屾姤閿欐椂 data 涔熸槸 Blob锛屽繀椤诲厛璇绘枃鏈啀瑙f瀽锛�
+    // 鍚﹀垯鎷夸笉鍒板悗绔湡瀹炲師鍥狅紝鍙細鏄剧ず绗肩粺鐨勨�滆纭宸插鍏ュ搴旀暟鎹�濄��
+    failWith(err, action) {
       if (err && err._toast) { this.loading = ''; return }
-      let msg = ''
-      const d = err && err.response && err.response.data
-      if (d && typeof d === 'object' && d.message) msg = d.message
-      this.$message.error('瀵煎嚭澶辫触锛�' + (msg || '璇风‘璁ゅ凡瀵煎叆瀵瑰簲鏁版嵁锛屾垨鏌ョ湅鍚庣鏃ュ織'))
-      this.loading = ''
+      const act = action || '瀵煎嚭'
+      const finish = (reason) => {
+        this.$message.error(act + '澶辫触锛�' + reason)
+        this.loading = ''
+      }
+      if (!err || !err.response) {
+        if (err && err.code === 'ECONNABORTED') { finish('璇锋眰瓒呮椂锛岃绋嶅悗閲嶈瘯'); return }
+        finish('鏃犳硶杩炴帴鏈嶅姟鍣紝璇锋鏌ョ綉缁滆繛鎺ワ紝鎴栫‘璁ゅ悗绔湇鍔℃槸鍚﹀凡鍚姩')
+        return
+      }
+      const d = err.response.data
+      const fallback = '璇风‘璁ゅ凡瀵煎叆瀵瑰簲鏁版嵁锛屾垨鏌ョ湅鍚庣鏃ュ織'
+      if (d && typeof d.text === 'function') {
+        Promise.resolve(d.text()).then(txt => finish(this.errReason(txt) || fallback)).catch(() => finish(fallback))
+        return
+      }
+      finish(this.errReason(typeof d === 'string' ? d : (d && d.message)) || fallback)
+    },
+    // 鍚庣寮傚父鍝嶅簲鍙兘鏄� JSON/HTML/绾枃鏈紝灏介噺鎻愬彇鍑哄彲璇荤殑鍘熷洜
+    errReason(raw) {
+      if (!raw) return ''
+      let text = String(raw).trim()
+      if (text.charAt(0) === '{' || text.charAt(0) === '[') {
+        try {
+          const j = JSON.parse(text)
+          if (j && j.message) return j.message
+        } catch (e) { /* 闈� JSON锛屾寜绾枃鏈鐞� */ }
+      }
+      text = text.replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim()
+      // 寮�鍙戜唬鐞�/缃戠粶灞傛姤閿欒浆鎴愪汉璇濓紝閬垮厤鐩存帴鎶� ECONNREFUSED 涔嬬被鎶涚粰鐢ㄦ埛
+      if (/ECONNREFUSED|ECONNRESET|Proxy error|socket hang up|Network Error|Failed to fetch/i.test(text)) {
+        return '鏃犳硶杩炴帴鏈嶅姟鍣紝璇锋鏌ョ綉缁滆繛鎺ワ紝鎴栫‘璁ゅ悗绔湇鍔℃槸鍚﹀凡鍚姩'
+      }
+      return text.length > 200 ? text.slice(0, 200) + '鈥�' : text
     },
     downloadBlob(res, fileName) {
       const isZip = /\.zip$/.test(fileName)
@@ -494,4 +605,19 @@
 @media (max-width: 900px) {
   .panel-head { flex-direction: column; align-items: flex-start; }
 }
+.wb-table th { background:#f5f7fa; }
+.wb-sec { background:#F7F9FC; font-weight:600; text-align:center; color:#303133; }
+.wb-label { color:#303133; }
+.wb-value { text-align:right; font-variant-numeric: tabular-nums; }
+.wb-yoy { text-align:right; color:#606266; }
+.wb-yoy.yoy-empty { color:#C0C4CC; }
+.wb-note { color:#E6A23C; font-size:12px; margin:2px 0 8px; }
 </style>
+
+<style>
+/* 棰勮鏁版嵁寮圭獥锛氬渾瑙� + 鍙�氳繃鏍囬鏍忔嫋鍔紙v-dialog-drag 鎸囦护锛夈��
+   涓嶈兘鍐欒繘 scoped锛歟l-dialog 榛樿 append-to-body锛孌OM 鎸傚湪 body 涓婏紝scoped 閫夋嫨鍣ㄥ尮閰嶄笉鍒般�� */
+.pv-dialog { border-radius: 10px; overflow: hidden; }
+.pv-dialog .el-dialog__header { cursor: move; user-select: none; -webkit-user-select: none; }
+.pv-dialog .el-dialog__headerbtn { cursor: pointer; }
+</style>
\ No newline at end of file

--
Gitblit v1.9.1