Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5bb31516a0 | |||
| 2560d9d529 | |||
| 6534723050 | |||
| f031501286 |
@@ -0,0 +1 @@
|
|||||||
|
2K94E8Rn63mn6Nys
|
||||||
+5
-4
@@ -25,10 +25,11 @@
|
|||||||
const code = urlParams.get('code');
|
const code = urlParams.get('code');
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
// 有 code → 进入授权 Loading 页处理
|
// 有 code → 进入授权 Loading 页处理,保留 code 参数
|
||||||
const loadingUrl = deviceId
|
let loadingUrl = '/pages/auth/loading?code=' + encodeURIComponent(code);
|
||||||
? `/pages/auth/loading?device_id=${deviceId}`
|
if (deviceId) {
|
||||||
: '/pages/auth/loading';
|
loadingUrl += '&device_id=' + deviceId;
|
||||||
|
}
|
||||||
uni.redirectTo({ url: loadingUrl });
|
uni.redirectTo({ url: loadingUrl });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -8,8 +8,8 @@ const dev = {
|
|||||||
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
// 网关地址(vms-gateway,端口 4001)— 用户授权、短信等接口走网关
|
||||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||||
|
|
||||||
// 授权回调地址(支付宝/微信 OAuth redirect_uri)
|
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||||
authRedirectUri: 'https://gateway.arklinksmart.cn/api/v1/user/auth/callback',
|
authRedirectUri: 'https://m.arklinksmart.cn/pages/auth/loading',
|
||||||
|
|
||||||
// 开发阶段硬编码 Token(生产环境应从登录流程获取)
|
// 开发阶段硬编码 Token(生产环境应从登录流程获取)
|
||||||
bearerToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlZXB2ZW5kaW5nIiwic3ViIjoiMTY0MDI0MTEyNiIsImZyb20iOiJwb3MiLCJyb2xlIjoicG9zIiwibWFpbmJvYXJkX2lkIjoiVDEwMDIiLCJwb3Nfc24iOiIxNjQwMjQxMTI2IiwiaWF0IjoxNzc4NDkxOTA3LCJleHAiOjE3NzkwOTY3MDd9.DjscZtrTCr30XOngToUifxoel4q2EGES_uqGQernkvg',
|
bearerToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImRlZXB2ZW5kaW5nIiwic3ViIjoiMTY0MDI0MTEyNiIsImZyb20iOiJwb3MiLCJyb2xlIjoicG9zIiwibWFpbmJvYXJkX2lkIjoiVDEwMDIiLCJwb3Nfc24iOiIxNjQwMjQxMTI2IiwiaWF0IjoxNzc4NDkxOTA3LCJleHAiOjE3NzkwOTY3MDd9.DjscZtrTCr30XOngToUifxoel4q2EGES_uqGQernkvg',
|
||||||
|
|||||||
+2
-2
@@ -8,8 +8,8 @@ const prod = {
|
|||||||
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
|
// 网关地址(vms-gateway)— 用户授权、短信等接口走网关
|
||||||
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
apiGatewayUrl: 'https://gateway.arklinksmart.cn',
|
||||||
|
|
||||||
// 授权回调地址(支付宝/微信 OAuth redirect_uri)
|
// 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面)
|
||||||
authRedirectUri: 'https://gateway.arklinksmart.cn/api/v1/user/auth/callback',
|
authRedirectUri: 'https://m.arklinksmart.cn/pages/auth/loading',
|
||||||
|
|
||||||
// 生产环境 Token 从登录流程获取,此处为空
|
// 生产环境 Token 从登录流程获取,此处为空
|
||||||
bearerToken: '',
|
bearerToken: '',
|
||||||
|
|||||||
@@ -21,9 +21,13 @@ export default {
|
|||||||
this.deviceId = options.device_id || '';
|
this.deviceId = options.device_id || '';
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
// 检查 URL 中是否有授权回调的 code
|
// 优先从页面参数获取 code(App.vue 跳转时带过来)
|
||||||
|
// 兜底从 URL search 参数获取(微信直接回调时)
|
||||||
|
let code = options.code || '';
|
||||||
|
if (!code) {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
const code = urlParams.get('code');
|
code = urlParams.get('code') || '';
|
||||||
|
}
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
// 有 code → 调用后端登录
|
// 有 code → 调用后端登录
|
||||||
@@ -56,9 +60,9 @@ export default {
|
|||||||
try {
|
try {
|
||||||
this.statusText = '正在获取授权...';
|
this.statusText = '正在获取授权...';
|
||||||
|
|
||||||
// 构建回调地址(当前页面地址)
|
// 回调地址必须是 HTTPS,使用配置文件中的地址
|
||||||
const redirectUri = encodeURIComponent(
|
const redirectUri = config.authRedirectUri || (
|
||||||
window.location.origin + window.location.pathname
|
window.location.origin.replace(/^http:/, 'https:') + window.location.pathname
|
||||||
);
|
);
|
||||||
|
|
||||||
const res = await gatewayGet('/api/v1/user/auth/url', {
|
const res = await gatewayGet('/api/v1/user/auth/url', {
|
||||||
|
|||||||
+25
-1
@@ -1,8 +1,31 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import uni from '@dcloudio/vite-plugin-uni'
|
import uni from '@dcloudio/vite-plugin-uni'
|
||||||
|
import { existsSync, readFileSync } from 'fs'
|
||||||
|
import { resolve } from 'path'
|
||||||
|
|
||||||
|
// 开发服务器:显式处理 public 目录下的静态文件,避免被 SPA history 路由拦截
|
||||||
|
function servePublicFiles() {
|
||||||
|
return {
|
||||||
|
name: 'serve-public-files',
|
||||||
|
configureServer(server) {
|
||||||
|
server.middlewares.use((req, res, next) => {
|
||||||
|
if (req.url) {
|
||||||
|
const filePath = resolve(__dirname, 'public', req.url.slice(1))
|
||||||
|
if (existsSync(filePath) && filePath.endsWith('.txt')) {
|
||||||
|
const content = readFileSync(filePath, 'utf-8')
|
||||||
|
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
|
||||||
|
res.end(content)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [uni()],
|
plugins: [servePublicFiles(), uni()],
|
||||||
css: {
|
css: {
|
||||||
preprocessorOptions: {
|
preprocessorOptions: {
|
||||||
scss: {
|
scss: {
|
||||||
@@ -10,4 +33,5 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
publicDir: 'public',
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user