Skip to content

Commit 665b85f

Browse files
committed
优化:用户登录界面样式优化
1 parent c9d94fa commit 665b85f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

electron/mapi/user/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ipcMain.handle('user:save', async (event, data) => {
8989

9090
const refresh = async () => {
9191
const result = await userInfoApi()
92+
// console.log('user.refresh', result)
9293
await save({
9394
apiToken: result.data.apiToken,
9495
user: result.data.user,
@@ -196,7 +197,9 @@ const post = async <T>(
196197
if (json.code) {
197198
// 未登录或登录过期
198199
if (json.code === 1001) {
199-
await refresh()
200+
if (userData.user && userData.user.id) {
201+
await refresh()
202+
}
200203
}
201204
if (option.catchException) {
202205
throw json.msg

src/pages/User/hook.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@ export const useUserPage = ({web, status}) => {
1313
const user = useUserStore()
1414
const canGoBack = ref(false)
1515

16-
const webUrlList = [
16+
const whiteUrl = [
1717
'/app_manager/user',
1818
'/member_vip',
1919
'/login',
2020
'/register',
2121
'/logout'
2222
]
23+
const urlMap = {
24+
'/app_manager/user': '/member',
25+
}
2326

2427
const getUrl = () => {
2528
const url = web.value.getURL()
2629
return new URL(url).pathname;
2730
}
2831

2932
const getCanGoBack = () => {
30-
if (webUrlList[0] === getUrl()) {
33+
if (whiteUrl[0] === getUrl()) {
3134
return false
3235
}
3336
return true
@@ -45,19 +48,30 @@ export const useUserPage = ({web, status}) => {
4548
web.value.executeJavaScript(`document.body.setAttribute('data-theme', 'dark');`)
4649
}
4750
})
51+
web.value.addEventListener('close', (event: any) => {
52+
if (web.value.isDevToolsOpened()) {
53+
web.value.closeDevTools()
54+
}
55+
})
4856
web.value.addEventListener('dom-ready', (e) => {
4957
// web.value.openDevTools()
5058
window.$mapi.user.refresh()
5159
canGoBack.value = getCanGoBack()
52-
web.value.insertCSS(`.pb-page-member-vip .top{ padding-left: 5rem; }`)
5360
web.value.executeJavaScript(`
5461
document.addEventListener('click', (event) => {
5562
const target = event.target;
5663
if (target.tagName !== 'A') return;
57-
const url = target.href
64+
let url = target.href
5865
if(url.startsWith('javascript:')) return;
59-
const urlPath = new URL(url).pathname;
60-
const whiteList = ${JSON.stringify(webUrlList)};
66+
let urlPath = new URL(url).pathname;
67+
const urlMap = ${JSON.stringify(urlMap)};
68+
if(urlMap[urlPath]) {
69+
urlPath = urlMap[urlPath];
70+
const urlNew = new URL(url);
71+
urlNew.pathname = urlPath;
72+
url = urlNew.toString();
73+
}
74+
const whiteList = ${JSON.stringify(whiteUrl)};
6175
if (whiteList.includes(urlPath)) return;
6276
event.preventDefault();
6377
window.$mapi.user.openWebUrl(url)

0 commit comments

Comments
 (0)