From efd3b57826a7ace8be29fea7d623944ea4065b05 Mon Sep 17 00:00:00 2001 From: chenxing Date: Sat, 19 Sep 2026 13:48:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(msgcenter):=20=E6=B6=88=E6=81=AF=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=20WS=20=E5=AE=9E=E6=97=B6=E6=8E=A8=E9=80=81=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=20+=20CI=20=E6=8E=A5=E5=85=A5=20projman=20=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=93=BE=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Header.vue:铃铛未读角标 + WS 客户端(25s 心跳/断线 5s 重连换新票/newMessage 红点+1+Notice 弹提示) - BaseApi.ts:getMsgCenterWsTicket(POST /api/msgCenter/wsTicket 代签一次性票据) - index.html:修复 lodash 引用路径(./libs/lodash.min.js,dev 404 致白屏) - CI:build.yml 照 notice/front 模板(构建→zip→Nexus front-hosted→webhook 建档); userhome deployMode=auto,webhook 后自动发布;凭据 prod.env+projman DB 直读(不走仓库 Secrets) --- .gitea/workflows/build.yml | 99 +++++++++++++++++ index.html | 3 +- src/api/BaseApi.ts | 47 ++++++++ src/components/Header.vue | 218 +++++++++++++++++++++++++++++-------- 4 files changed, 323 insertions(+), 44 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index e69de29..4219766 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -0,0 +1,99 @@ +name: build + +# 前端应用 CI(照 notice/front build.yml 模板):构建 → 打包 zip → 推 Nexus raw → webhook 通知 projman 建档 +# 触发:push 到 main / 手动 Run workflow +# userhome 应用 deployMode=auto:webhook 建档后 projman 自动发布前端版本(下载 zip → persist → Caddy 切链) +# 凭据不走仓库 Secrets:runner 与 projman 同机,Nexus 凭据与部署令牌均从宿主 prod.env / projman DB 直读 +# (NEXUS_USER 缺省 admin;DEPLOY_TOKEN = app_identity code=proj11-deploy 的明文,与 webhook 校验同源) + +on: + push: + branches: [ main ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + container: + image: docker:24 + options: --network infra-infra-net + steps: + - name: 安装 git / curl / zip(alpine) + run: apk add --no-cache git curl zip + + # 内网 Gitea 无法访问 GitHub 拉 actions/checkout,手动 clone 本仓库 + - name: 拉取源码(内网无 GitHub,手动 clone 本仓库) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git clone --depth 1 --branch main "http://x-access-token:${GITHUB_TOKEN}@gitea.yunhaixingtong.com/${{ github.repository }}.git" /tmp/src + cp -a /tmp/src/. . + rm -rf /tmp/src + COMMIT_MSG=$(git log -1 --pretty=%s | tr '\n' ' ' | sed 's/["\\]/ /g' | cut -c1-200) + echo "COMMIT_MSG=${COMMIT_MSG}" >> "$GITHUB_ENV" + + # 凭据:宿主 prod.env(Nexus)+ projman DB(部署令牌);经 docker.sock 起一次性容器读取,不回显 + - name: 读取凭据(prod.env + projman DB) + run: | + set -e + PWD_DB=$(docker run --rm -v /opt/docker/projman-deploy:/pe:ro alpine sh -c "grep '^PROJMAN_DB_PASSWORD=' /pe/prod.env | head -1 | cut -d= -f2-") + NXUSER=$(docker run --rm -v /opt/docker/projman-deploy:/pe:ro alpine sh -c "grep '^PROJMAN_NEXUS_USER=' /pe/prod.env | head -1 | cut -d= -f2-") + NXPASS=$(docker run --rm -v /opt/docker/projman-deploy:/pe:ro alpine sh -c "grep '^PROJMAN_NEXUS_PASSWORD=' /pe/prod.env | head -1 | cut -d= -f2-") + TOKEN=$(docker exec -e MYSQL_PWD="$PWD_DB" mysql8 mysql -uroot -N -e \ + "select secret_text from app_identity where code='proj11-deploy' and purpose='deploy_token' limit 1" bsch_projman \ + | tr -d '[:space:]') + [ -n "$NXUSER" ] || NXUSER=admin + [ -n "$NXPASS" ] || { echo 'Nexus 凭据缺失'; exit 1; } + [ -n "$TOKEN" ] || { echo 'userhome 部署令牌缺失'; exit 1; } + echo "NEXUS_USER=${NXUSER}" >> "$GITHUB_ENV" + echo "NEXUS_PASSWORD=${NXPASS}" >> "$GITHUB_ENV" + echo "DEPLOY_TOKEN=${TOKEN}" >> "$GITHUB_ENV" + + # 前端构建:独立 node 容器(容器名全局唯一,防并发互踩——2026-09-10 三仓同推事故) + - name: 构建前端(node 容器) + run: | + set -e + BUILD_CONTAINER="frontbuild-${GITHUB_RUN_ID:-0}-$(date +%s)" + echo "BUILD_CONTAINER=${BUILD_CONTAINER}" + docker rm -f "$BUILD_CONTAINER" 2>/dev/null || true + docker run -d --name "$BUILD_CONTAINER" -w /build node:20 sleep 3600 + docker cp "${PWD}/." "$BUILD_CONTAINER":/build/ + docker exec "$BUILD_CONTAINER" sh -c ' + set -e + cd /build + if [ -f .npmrc ]; then sed -i "/SASS_BINARY_PATH/d" .npmrc; fi + npm ci --no-audit --no-fund + npm run build + ' + echo "=== dist 产物 ===" + docker exec "$BUILD_CONTAINER" sh -c 'ls -la /build/dist/ | head -20' + docker cp "$BUILD_CONTAINER":/build/dist ./dist + docker rm -f "$BUILD_CONTAINER" + echo "BUILD CHECK OK" + + # 打包 dist → zip(vite outDir 直出 dist/,zip 根目录直接是 index.html/css/js) + - name: 打包产物 + run: | + TAG=$(echo "$GITHUB_SHA" | cut -c1-8) + ZIP_FILE="userhome-front-${TAG}.zip" + cd dist && zip -r "../${ZIP_FILE}" . && cd .. + echo "ZIP_FILE=${ZIP_FILE}" >> "$GITHUB_ENV" + echo "TAG=${TAG}" >> "$GITHUB_ENV" + ls -la "${ZIP_FILE}" + + - name: 上传产物到 Nexus + run: | + set -e + NEXUS_URL="http://nexus.yunhaixingtong.com:8081/repository/front-hosted/${ZIP_FILE}" + curl -sSf -X PUT -u "${NEXUS_USER}:${NEXUS_PASSWORD}" --upload-file "${ZIP_FILE}" "${NEXUS_URL}" + echo "NEXUS_URL=${NEXUS_URL}" >> "$GITHUB_ENV" + echo "uploaded to ${NEXUS_URL}" + + # 通知 projman:webhook 建档(type=front);userhome deployMode=auto → 建档后自动发布 + - name: 通知 projman 建档(auto 发布) + run: | + curl -sSf -X POST "http://192.168.10.160:8090/projman/api/deploy/webhook" \ + -H "Content-Type: application/json" \ + -H "X-Deploy-Token: ${DEPLOY_TOKEN}" \ + -d "{\"app\":\"userhome\",\"front\":\"front\",\"tag\":\"${TAG}\",\"sha\":\"${GITHUB_SHA}\",\"message\":\"${COMMIT_MSG}\",\"nexusUrl\":\"${NEXUS_URL}\"}" + echo "webhook 建档完成,auto 模式将自动发布" diff --git a/index.html b/index.html index 29e4ed8..be0fef5 100644 --- a/index.html +++ b/index.html @@ -29,7 +29,8 @@ <%- title %> - + + diff --git a/src/api/BaseApi.ts b/src/api/BaseApi.ts index 2ecdfe6..5ec43ac 100644 --- a/src/api/BaseApi.ts +++ b/src/api/BaseApi.ts @@ -95,6 +95,53 @@ class Base extends Abstract { return this.postRequest({ url }); } + // ===== 消息中心代理(§3.5:经后端签名代理 UserMsg,前端不直连)===== + + /** + * 消息中心分页列表({total, list[]};元素含改写后的绝对 jumpUrl) + * @memberof Basic + */ + getMsgCenterList(params: PageParams) { + const url = path + "/msgCenter/list"; + return this.getRequest({ url, params }); + } + + /** + * 铃铛摘要:未读数 + 各应用待办角标 + * @memberof Basic + */ + getMsgCenterSummary() { + const url = path + "/msgCenter/summary"; + return this.getRequest<{ unreadCount: number; todos: { appKey: string; count: number }[] }>({ url }); + } + + /** + * WS 实时推送握手地址(UserMsg 一次性票据;url=null 表示未配置/不可达,走手动刷新兜底) + * @memberof Basic + */ + getMsgCenterWsTicket() { + const url = path + "/msgCenter/wsTicket"; + return this.getRequest<{ url: string | null }>({ url }); + } + + /** + * 消息中心:已读某一条(按登录人代理) + * @memberof Basic + */ + readMsgCenter(msgId: number) { + const url = path + "/msgCenter/read"; + return this.postRequest({ url, params: { msgId } }); + } + + /** + * 消息中心:全部已读 + * @memberof Basic + */ + readMsgCenterAll() { + const url = path + "/msgCenter/readAll"; + return this.postRequest({ url }); + } + /** * 修改密码 * @memberof Basic diff --git a/src/components/Header.vue b/src/components/Header.vue index 874492a..e957729 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -27,33 +27,35 @@
- + + +