Browse Source

feat: 修复画像留资查看问题、新增异常监控

zhangyuhan 1 year ago
parent
commit
eb099545cc

+ 1 - 0
apps/bigmember_pc/.env.development

@@ -3,3 +3,4 @@ VITE_APP_BASE_API='/dev-api'
 VITE_APP_BASE_URL='/swordfish/page_big_pc'
 VITE_APP_BASE_PUBLIC='/'
 VITE_APP_WORK_DESKTOP_URL='/page_workDesktop/work-bench/app'
+VITE_APP_GIT_BRANCH='v0.0.1'

+ 1 - 0
apps/bigmember_pc/.env.production

@@ -3,3 +3,4 @@ VITE_APP_BASE_API=''
 VITE_APP_BASE_URL='/page_big_pc'
 VITE_APP_BASE_PUBLIC='/page_big_pc/'
 VITE_APP_WORK_DESKTOP_URL='/page_workDesktop/work-bench/app/big'
+VITE_APP_GIT_BRANCH='v1.0.54.1'

+ 4 - 1
apps/bigmember_pc/package.json

@@ -4,12 +4,15 @@
   "private": true,
   "scripts": {
     "dev": "vite",
-    "build": "vite build",
+    "build": "pnpm run update && pnpm run build:vite",
+    "build:vite": "vite build",
+    "update": "node ./scripts/updateGitInfo.js",
     "preview": "vite preview --port 4173",
     "lint": "eslint . --ext .vue,.js,.jsx --fix",
     "format": "prettier --write \"./**/*.{,vue,ts,js,json,md}\""
   },
   "dependencies": {
+    "@sentry/vue": "^7.64.0",
     "@jy/util": "workspace:^",
     "@jy/data-models": "workspace:^",
     "@jy/pc-ui": "workspace:^",

+ 52 - 0
apps/bigmember_pc/scripts/updateGitInfo.js

@@ -0,0 +1,52 @@
+const { exec } = require('child_process')
+const fs = require('fs')
+
+const getGitBranch = () => {
+  return new Promise((resolve, reject) => {
+    exec(
+      'git symbolic-ref --quiet --short HEAD || git describe --all --exact-match HEAD',
+      (error, stdout, stderr) => {
+        if (error) {
+          reject(error)
+        } else {
+          const branch = stdout.trim()
+          resolve(branch)
+        }
+      }
+    )
+  })
+}
+
+const extractVersion = (branch) => {
+  const versionRegex = /(v.*?)$/
+  const matches = branch.match(versionRegex)
+  return matches ? matches[0] : ''
+}
+
+const updateEnvFile = (branch) => {
+  try {
+    const envFilePath = '.env.production'
+    const existingContent = fs.readFileSync(envFilePath, 'utf8')
+    const updatedBranch = extractVersion(branch)
+    const updatedContent = existingContent.replace(
+      /(VITE_APP_GIT_BRANCH=).*/,
+      `$1'${updatedBranch}'`
+    )
+    fs.writeFileSync(envFilePath, updatedContent)
+    console.log(
+      'Git 分支信息已更新到 .env.production 文件',
+      branch,
+      updatedBranch
+    )
+  } catch (error) {
+    console.error('更新 .env.production 文件失败:', error)
+  }
+}
+
+getGitBranch()
+  .then((branch) => {
+    updateEnvFile(branch)
+  })
+  .catch((error) => {
+    console.error('获取 Git 分支失败:', error)
+  })

+ 4 - 0
apps/bigmember_pc/src/main.js

@@ -21,6 +21,7 @@ import '@/utils/directive'
 import '@/utils/prototype'
 import MetaInfo from 'vue-meta-info'
 import JyIcon from '@jianyu/icon' // 需要单独引入icon/index.css
+import { initSentry } from './sentry'
 
 Vue.use(VueCookies)
 Vue.use(Loading.directive)
@@ -62,4 +63,7 @@ const app = easySubAppRegister(
 
 global.legacyQiankun[name].lifecyle = app
 
+// Sentry 异常监控
+initSentry()
+
 export const { bootstrap, mount, unmount } = app

+ 15 - 0
apps/bigmember_pc/src/sentry.js

@@ -0,0 +1,15 @@
+import * as Sentry from '@sentry/vue'
+
+export function initSentry() {
+  if (!import.meta.env.DEV) {
+    Sentry.init({
+      dsn: 'https://1009883edc154953bec82b5e9ec88bce@jysentry.jydev.jianyu360.cn/7',
+      release: import.meta.env.VITE_APP_GIT_BRANCH,
+      environment: 'produce',
+      sampleRate: 0.02
+    })
+    Sentry.setTag('url', location.href)
+    const id = document.cookie.match(/(^|;)\s*ud_safe\s*=\s*([^;]+)/)
+    Sentry.setUser({ id: id && id[2] })
+  }
+}

+ 15 - 3
apps/bigmember_pc/src/views/portrayal/UnitPortrayal.vue

@@ -4,7 +4,7 @@
     :needAd="layoutNeedAd"
     :contentWithState="layoutContentWithState"
   >
-    <div class="unit-portrayal-content" v-loading="loading">
+    <div class="unit-portrayal-content" v-loading="pageLoading">
       <div class="unit-type">
         <div class="u-top-container">
           <h1 class="u-name">{{ info.buyerName }}</h1>
@@ -744,7 +744,8 @@ export default {
         visited: false,
         balance: 0 // 剩余次数
       }, // 画像访问量
-      freeTrial: false,
+      freeTrial: true,
+      freeTrialLoaded: false,
       showFreeOpen: false,
       sendData: {
         type: 'UnitPortrayal',
@@ -831,6 +832,12 @@ export default {
     isFreeOrNoLogin() {
       return this.userInfo.isFree || !this.loginFlag
     },
+    pageLoading () {
+      return this.loading || !this.getTrailLoaded
+    },
+    getTrailLoaded () {
+      return this.freeTrialLoaded
+    },
     conf7() {
       const power = this.userInfo.power
       if (power) {
@@ -1336,7 +1343,12 @@ export default {
     },
     // 获取免费用户是否体验过该采购单位
     getIsTrail(data) {
-      this.freeTrial = data ? data : false
+      if (typeof data === 'boolean') {
+        this.freeTrial = data
+      } else {
+        this.freeTrial = false
+      }
+      this.freeTrialLoaded = true
     },
     // 等待画像接口请求完成再调用usage接口
     getUse(data) {

+ 1 - 3
apps/bigmember_pc/src/views/portrayal/components/UnitChart.vue

@@ -1010,9 +1010,7 @@ export default {
       if (res.error_code === 0) {
         if (res.data && Object.keys(res.data).length > 0) {
           this.showChart = true
-          if (res.data.onTrial) {
-            this.$emit('isTrial', res.data.onTrial)
-          }
+          this.$emit('isTrial', res.data?.onTrial || false)
           this.initData('', res.data)
         } else {
           this.getSectionChartData('a', newval)

+ 9 - 6
pnpm-lock.yaml

@@ -72,6 +72,9 @@ importers:
       '@jy/util':
         specifier: workspace:^
         version: link:../../packages/util
+      '@sentry/vue':
+        specifier: ^7.64.0
+        version: 7.64.0(vue@2.7.16)
       dayjs:
         specifier: ^1.11.7
         version: 1.11.8
@@ -5804,7 +5807,7 @@ packages:
       regenerator-runtime: 0.13.11
       systemjs: 6.14.3
       terser: 5.19.2
-      vite: 4.3.9(sass@1.71.1)(terser@5.19.2)
+      vite: 4.3.9(less@4.1.3)(sass@1.63.2)(terser@5.19.2)
     transitivePeerDependencies:
       - supports-color
     dev: true
@@ -5847,7 +5850,7 @@ packages:
       vite: ^3.0.0 || ^4.0.0
       vue: ^2.7.0-0
     dependencies:
-      vite: 4.3.9(sass@1.71.1)(terser@5.19.2)
+      vite: 4.3.9(less@4.1.3)(sass@1.63.2)(terser@5.19.2)
       vue: 2.7.16
     dev: true
 
@@ -7760,8 +7763,8 @@ packages:
     peerDependencies:
       postcss: ^8.1.0
     dependencies:
-      browserslist: 4.23.0
-      caniuse-lite: 1.0.30001591
+      browserslist: 4.21.9
+      caniuse-lite: 1.0.30001517
       fraction.js: 4.2.0
       normalize-range: 0.1.2
       picocolors: 1.0.0
@@ -15791,7 +15794,7 @@ packages:
       '@types/eslint': 8.44.1
       eslint: 8.37.0
       rollup: 2.79.1
-      vite: 4.3.9(sass@1.71.1)(terser@5.19.2)
+      vite: 4.3.9(less@4.1.3)(sass@1.63.2)(terser@5.19.2)
     dev: true
 
   /vite-plugin-externals@0.6.2(vite@4.3.9):
@@ -15804,7 +15807,7 @@ packages:
       es-module-lexer: 0.4.1
       fs-extra: 10.1.0
       magic-string: 0.25.9
-      vite: 4.3.9(sass@1.71.1)(terser@5.19.2)
+      vite: 4.3.9(less@4.1.3)(sass@1.63.2)(terser@5.19.2)
     dev: true
 
   /vite-plugin-html-redirect@1.0.4: