Compare commits

..

8 Commits

Author SHA1 Message Date
kk b336b901d3 前端传入state
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 48s
2026-07-17 14:40:21 +08:00
kk 9439bcf9d7 解析state参数
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 50s
2026-07-17 12:20:20 +08:00
kk d862cad1a0 授权回调时code参数名支持支付宝的auth_code
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 39s
2026-07-15 18:02:48 +08:00
kk 85d5193071 修改app_no_map值
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 45s
2026-07-15 17:57:23 +08:00
kk 9551d9d8b2 传入对应环境的scope参数
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 49s
2026-07-15 17:37:23 +08:00
kk 81bec5ba3b 开门增加来源
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 45s
2026-07-15 17:02:07 +08:00
kk 729bc3c70e 支持预发布环境构建
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 39s
2026-07-15 10:46:02 +08:00
kk 2e84a00f6e 支持预发布环境部署
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 40s
2026-07-15 10:25:08 +08:00
8 changed files with 123 additions and 64 deletions
+12 -1
View File
@@ -92,11 +92,15 @@ jobs:
# 3. 安装依赖 & 构建 Uni-app (H5) # 3. 安装依赖 & 构建 Uni-app (H5)
############################################### ###############################################
- name: Install dependencies and Build H5 - name: Install dependencies and Build H5
env:
DEPLOY_ENV: ${{ steps.detect.outputs.env }}
run: | run: |
set -e set -e
# pnpm真实路径 # pnpm真实路径
PNPM_PATH="/root/.nvm/versions/node/v20.20.2/bin/pnpm" PNPM_PATH="/root/.nvm/versions/node/v20.20.2/bin/pnpm"
echo "构建环境: DEPLOY_ENV=$DEPLOY_ENV"
# 1. 配置镜像并安装依赖 # 1. 配置镜像并安装依赖
$PNPM_PATH config set registry https://registry.npmmirror.com $PNPM_PATH config set registry https://registry.npmmirror.com
$PNPM_PATH install --frozen-lockfile $PNPM_PATH install --frozen-lockfile
@@ -110,9 +114,16 @@ jobs:
- name: Upload dist to server - name: Upload dist to server
run: | run: |
TARGET="${{ steps.detect.outputs.target }}" TARGET="${{ steps.detect.outputs.target }}"
ENV_NAME="${{ steps.detect.outputs.env }}"
# 请根据你的实际构建输出路径调整 # 请根据你的实际构建输出路径调整
H5_SOURCE_DIR="dist/build/h5" H5_SOURCE_DIR="dist/build/h5"
WEB_ROOT="${{ vars.PROJECT_DIR }}"
# 根据发布类型选择项目路径
if [ "$ENV_NAME" = "staging" ]; then
WEB_ROOT="${{ vars.STG_PROJECT_DIR }}"
else
WEB_ROOT="${{ vars.PROJECT_DIR }}"
fi
echo "部署到: $TARGET" echo "部署到: $TARGET"
echo "源目录: $H5_SOURCE_DIR" echo "源目录: $H5_SOURCE_DIR"
+3 -1
View File
@@ -131,6 +131,7 @@
<script> <script>
import { get, post } from '@/utils/request.js'; import { get, post } from '@/utils/request.js';
import { detectPlatform } from '@/utils/env.js';
export default { export default {
props: { props: {
@@ -163,7 +164,8 @@ export default {
const res = await post('/device-scan/open', { const res = await post('/device-scan/open', {
device_id: this.deviceId, device_id: this.deviceId,
door_index: 0, door_index: 0,
user_id: uid user_id: uid,
platform: detectPlatform()
}); });
const ret = res.data || {}; const ret = res.data || {};
+16 -2
View File
@@ -1,16 +1,30 @@
/** /**
* 环境配置入口 * 环境配置入口
* 根据编译模式自动选择 dev / prod 配置 * 根据编译模式自动选择 dev / staging / prod 配置
*
* DEPLOY_ENV 环境变量:
* - 'staging' → 预发布环境
* - 'production' → 生产环境(默认)
* - 未设置且 NODE_ENV !== 'production' → 开发环境
*/ */
import common from './index.js'; import common from './index.js';
import dev from './dev.js'; import dev from './dev.js';
import staging from './staging.js';
import prod from './prod.js'; import prod from './prod.js';
// uni-app 编译时通过 define 注译 __UNI_PLATFORM__ // uni-app 编译时通过 define 注译 __UNI_PLATFORM__
// H5 开发模式下 process.env.NODE_ENV === 'development' // H5 开发模式下 process.env.NODE_ENV === 'development'
const isProd = process.env.NODE_ENV === 'production'; const isProd = process.env.NODE_ENV === 'production';
const deployEnv = process.env.DEPLOY_ENV;
const envConfig = isProd ? prod : dev; let envConfig;
if (!isProd) {
envConfig = dev;
} else if (deployEnv === 'staging') {
envConfig = staging;
} else {
envConfig = prod;
}
const config = { const config = {
...common, ...common,
+20
View File
@@ -0,0 +1,20 @@
/**
* 预发布环境配置
*/
const staging = {
// 业务 API 地址(vms-api
apiBaseUrl: 'https://vmsapi.arklinksmart.cn',
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
authRedirectUri: 'https://pre-m.arklinksmart.cn/pages/auth/loading',
// 生产环境 Token 从登录流程获取,此处为空
bearerToken: '',
enableRequestLog: false,
};
export default staging;
+49 -35
View File
@@ -30,10 +30,29 @@ export default {
} }
// 从 URL 参数获取 codeApp.vue 跳转时带过来) // 从 URL 参数获取 codeApp.vue 跳转时带过来)
let code = options.code || ''; // 支付宝回调参数名是 auth_code,微信是 code
let code = options.code || options.auth_code || '';
if (!code) { if (!code) {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
code = urlParams.get('code') || ''; code = urlParams.get('code') || urlParams.get('auth_code') || '';
}
// 解析 state 参数(OAuth 标准保证 state 原样回传,包含 action 和 device_id
if (!this.action || !this.deviceId) {
const stateRaw = options.state || '';
if (stateRaw) {
try {
const stateObj = JSON.parse(decodeURIComponent(stateRaw));
if (!this.action && stateObj.action) {
this.action = stateObj.action;
}
if (!this.deviceId && stateObj.device_id) {
this.deviceId = stateObj.device_id;
}
} catch (_) {
// state 解析失败,继续用 localStorage 兜底
}
}
} }
// 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理) // 兜底:从 localStorage 恢复(页面复用时 onLoad 不触发,localStorage 由跳转函数清理)
@@ -97,29 +116,26 @@ export default {
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
); );
// 使用 snsapi_base 静默授权,不弹窗 // 静默授权:微信用 snsapi_base,支付宝用 auth_base
const scopes = platform === 'alipay' ? 'auth_base' : 'snsapi_base';
// 构建 state(包含 device_id,回调时原样回传)
const stateObj = {};
if (this.deviceId) {
stateObj.device_id = this.deviceId;
}
const res = await gatewayGet('/api/v1/user/auth/url', { const res = await gatewayGet('/api/v1/user/auth/url', {
app_no: appNo, app_no: appNo,
scopes: 'snsapi_base', scopes: scopes,
redirect_uri: redirectUri, redirect_uri: redirectUri,
state: Object.keys(stateObj).length > 0 ? JSON.stringify(stateObj) : '',
}); });
const data = res.data || {}; const data = res.data || {};
if (data.code === 0 && data.data && data.data.auth_url) { if (data.code === 0 && data.data && data.data.auth_url) {
// 通过 state 传递 device_idOAuth 标准保证 state 原样回传) // 后端已将 state 写入授权 URL,直接跳转
let authUrl = data.data.auth_url; window.location.href = data.data.auth_url;
if (this.deviceId) {
const stateVal = encodeURIComponent(JSON.stringify({ device_id: this.deviceId }));
try {
const urlObj = new URL(authUrl);
urlObj.searchParams.set('state', stateVal);
authUrl = urlObj.toString();
} catch (_) {
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
}
}
// 跳转微信授权页(静默,不弹窗)
window.location.href = authUrl;
} else { } else {
uni.showToast({ title: data.message || '获取授权失败', icon: 'none' }); uni.showToast({ title: data.message || '获取授权失败', icon: 'none' });
setTimeout(() => this.goToScan(), 1500); setTimeout(() => this.goToScan(), 1500);
@@ -154,6 +170,7 @@ export default {
// 立即清除 URL 中的 code 参数,避免刷新重复处理 // 立即清除 URL 中的 code 参数,避免刷新重复处理
const url = new URL(window.location.href); const url = new URL(window.location.href);
url.searchParams.delete('code'); url.searchParams.delete('code');
url.searchParams.delete('auth_code');
url.searchParams.delete('state'); url.searchParams.delete('state');
window.history.replaceState({}, '', url.toString()); window.history.replaceState({}, '', url.toString());
@@ -256,30 +273,26 @@ export default {
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
); );
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user
const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo';
// 构建 state(包含 action 和 device_id,回调时原样回传)
const stateObj = { action: 'userinfo' };
if (this.deviceId) {
stateObj.device_id = this.deviceId;
}
const res = await gatewayGet('/api/v1/user/auth/url', { const res = await gatewayGet('/api/v1/user/auth/url', {
app_no: appNo, app_no: appNo,
scopes: 'snsapi_userinfo', scopes: scopes,
redirect_uri: redirectUri, redirect_uri: redirectUri,
state: JSON.stringify(stateObj),
}); });
const data = res.data || {}; const data = res.data || {};
if (data.code === 0 && data.data && data.data.auth_url) { if (data.code === 0 && data.data && data.data.auth_url) {
// 通过 state 传递 action 和 device_idOAuth 标准保证 state 原样回传) // 后端已将 state 写入授权 URL,直接跳转
const stateObj = { action: 'userinfo' }; window.location.href = data.data.auth_url;
if (this.deviceId) {
stateObj.device_id = this.deviceId;
}
const stateVal = encodeURIComponent(JSON.stringify(stateObj));
let authUrl = data.data.auth_url;
try {
const urlObj = new URL(authUrl);
urlObj.searchParams.set('state', stateVal);
authUrl = urlObj.toString();
} catch (_) {
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
}
// 跳转微信授权页(弹窗确认)
window.location.href = authUrl;
} else { } else {
uni.showToast({ title: data.message || '获取授权失败', icon: 'none' }); uni.showToast({ title: data.message || '获取授权失败', icon: 'none' });
setTimeout(() => this.goToHomeWithAction(), 1500); setTimeout(() => this.goToHomeWithAction(), 1500);
@@ -313,6 +326,7 @@ export default {
// 立即清除 URL 中的 code/action 参数,避免刷新重复处理 // 立即清除 URL 中的 code/action 参数,避免刷新重复处理
const url = new URL(window.location.href); const url = new URL(window.location.href);
url.searchParams.delete('code'); url.searchParams.delete('code');
url.searchParams.delete('auth_code');
url.searchParams.delete('state'); url.searchParams.delete('state');
url.searchParams.delete('action'); url.searchParams.delete('action');
window.history.replaceState({}, '', url.toString()); window.history.replaceState({}, '', url.toString());
+15 -21
View File
@@ -344,34 +344,28 @@ export default {
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
); );
// 获取非静默授权链接(会弹窗确认 // 构建 state(包含 action 和 device_id,回调时原样回传
const stateObj = { action: 'userinfo' };
if (this.deviceId) {
stateObj.device_id = this.deviceId;
}
// 用户信息授权:微信用 snsapi_userinfo,支付宝用 auth_user
const platform = uni.getStorageSync('platform') || 'wechat';
const scopes = platform === 'alipay' ? 'auth_user' : 'snsapi_userinfo';
const res = await gatewayGet('/api/v1/user/auth/url', { const res = await gatewayGet('/api/v1/user/auth/url', {
app_no: appNo, app_no: appNo,
scopes: 'snsapi_userinfo', scopes: scopes,
redirect_uri: redirectUri, redirect_uri: redirectUri,
state: JSON.stringify(stateObj),
}); });
const data = res.data || {}; const data = res.data || {};
if (data.code === 0 && data.data && data.data.auth_url) { if (data.code === 0 && data.data && data.data.auth_url) {
// 通过 state 传递 action 和 device_idOAuth 标准保证 state 原样回传) console.log('[index] 跳转授权页:', data.data.auth_url);
const stateObj = { action: 'userinfo' }; // 后端已将 state 写入授权 URL,直接跳转
if (this.deviceId) { window.location.href = data.data.auth_url;
stateObj.device_id = this.deviceId;
}
const stateVal = encodeURIComponent(JSON.stringify(stateObj));
// 解析 auth_url,安全地设置 state 参数(避免重复)
let authUrl = data.data.auth_url;
try {
const urlObj = new URL(authUrl);
urlObj.searchParams.set('state', stateVal);
authUrl = urlObj.toString();
} catch (_) {
// URL 解析失败时直接拼接
authUrl += (authUrl.includes('?') ? '&' : '?') + 'state=' + stateVal;
}
console.log('[index] 跳转授权页:', authUrl);
// 跳转微信授权页(弹窗确认)
window.location.href = authUrl;
} else { } else {
console.warn('[index] 获取授权链接失败:', data.message); console.warn('[index] 获取授权链接失败:', data.message);
} }
+3 -3
View File
@@ -6,9 +6,9 @@
// app_no 编码表:platform + terminalType → app_no // app_no 编码表:platform + terminalType → app_no
const APP_NO_MAP = { const APP_NO_MAP = {
'wechat_h5': '60000001102001', 'wechat_h5': '60000001102001',
'wechat_mp': '600102101', 'wechat_mp': '60000001102101',
'alipay_h5': '600112001', 'alipay_h5': '60000001112001',
'alipay_mp': '600112101', 'alipay_mp': '60000001112101',
}; };
/** /**
+4
View File
@@ -26,6 +26,10 @@ function servePublicFiles() {
export default defineConfig({ export default defineConfig({
plugins: [servePublicFiles(), uni()], plugins: [servePublicFiles(), uni()],
// 将构建时的 DEPLOY_ENV 环境变量注入到客户端代码中
define: {
'process.env.DEPLOY_ENV': JSON.stringify(process.env.DEPLOY_ENV || ''),
},
css: { css: {
preprocessorOptions: { preprocessorOptions: {
scss: { scss: {