Skip to content

Commit e040546

Browse files
committed
✨ 优化后端自动校验域名是否设置正确的功能,不使用强弹窗提示,而是在后台设置页面显示提示信息。
1 parent 1815327 commit e040546

File tree

1 file changed

+73
-28
lines changed

1 file changed

+73
-28
lines changed

src/pages/admin/site-setting.vue

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,39 @@
1717
<z-form-item prop="domain" label="后端站点域名">
1818
<el-input id="domain" :prefix-icon="Link" v-model="data.domain"/>
1919
<template #tips>此地址用于生成直链及本次存储下载使用,请务必保持和服务端地址一样 (需写 http(s):// 协议头)</template>
20+
<el-popover placement="right" :width="400" trigger="click">
21+
<template #reference>
22+
<div v-show="fixDomain.flag" class="mt-2">
23+
<span class="text-red-500 text-sm">设置异常,点击查看</span>
24+
<ExclamationIcon class="inline w-5 text-red-500"/>
25+
</div>
26+
</template>
27+
<div class="text-sm">
28+
<div class="mb-2">检测到设置异常,实际后端域名应为 <span class="text-red-500">{{ fixDomain.except }}</span>,是否需要修复?(不修正可能会影响下载、文件夹加密和文档预览功能)</div>
29+
<div class="flex justify-end">
30+
<el-button size="small" type="warning" :icon="BadgeCheckIcon" @click="fixDomain.action">自动修正</el-button>
31+
</div>
32+
</div>
33+
</el-popover>
2034
</z-form-item>
2135

2236
<z-form-item prop="frontDomain" label="前端站点域名">
2337
<el-input :prefix-icon="Link" v-model="data.frontDomain"/>
2438
<template #tips>前后端分离后,需配置此地址,会影响 401、403、404 页面的跳转 (需写 http(s):// 协议头,未前后端分离请保持为空)</template>
39+
<el-popover placement="right" :width="400" trigger="click">
40+
<template #reference>
41+
<div v-show="fixFrontDomain.flag" class="mt-2">
42+
<span class="text-red-500 text-sm">设置异常,点击查看</span>
43+
<ExclamationIcon class="inline w-5 text-red-500"/>
44+
</div>
45+
</template>
46+
<div class="text-sm">
47+
<div class="mb-2">检测到设置异常,实际前端域名应为 <span class="text-red-500">{{ fixFrontDomain.except }}</span>,是否需要修复?(不修正会影响 401、403、404 页面的跳转功能)</div>
48+
<div class="flex justify-end">
49+
<el-button size="small" type="warning" :icon="BadgeCheckIcon" @click="fixFrontDomain.action">自动修正</el-button>
50+
</div>
51+
</div>
52+
</el-popover>
2553
</z-form-item>
2654

2755
<z-form-item prop="avatar" label="头像地址">
@@ -91,49 +119,66 @@ let dataRules = ref({
91119
92120
const siteSettingForm = ref();
93121
const saveForm = () => {
122+
document.querySelector(".z-form").click();
94123
siteSettingForm.value.validate(checked => {
95124
if (checked) {
96125
saveData();
97126
}
98127
})
99128
}
100129
130+
let fixDomain = ref({
131+
flag: false,
132+
except: '',
133+
action: () => {}
134+
});
135+
let fixFrontDomain = ref({
136+
flag: false,
137+
except: '',
138+
action: () => {}
139+
});
101140
102141
watch(() => dataLoading.value, (newVal, oldValue) => {
103142
// 如果是刚加载完成, 则检测域名配置是否正确.
104143
if (oldValue === true) {
144+
// 校验后端域名
105145
let serverDomain = globalConfigStore.zfileConfig.baseUrl || window.location.origin;
106146
let siteDomain = data.value.domain;
107-
108147
if (serverDomain !== siteDomain) {
109-
ElMessageBox.confirm(`检测到服务端地址为 ${serverDomain},当前配置站点域名为 ${siteDomain},是否自动进行修正?(不修正可能会影响下载、文件夹加密和文档预览功能)`, '提示', {
110-
confirmButtonText: '确定',
111-
cancelButtonText: '取消',
112-
type: 'warning',
113-
callback: action => {
114-
if (action === 'confirm') {
115-
data.value.domain = serverDomain;
116-
saveForm();
117-
}
118-
}
119-
});
120-
} else {
121-
let siteFrontDomain = data.value.frontDomain;
122-
let origin = window.location.origin;
123-
if (globalConfigStore.zfileConfig.baseUrl !== '' && siteFrontDomain !== origin) {
124-
ElMessageBox.confirm(`检测到当前为前后端分离模式,访问域名为 ${origin},当前配置前端站点域名为 ${siteFrontDomain},是否自动进行修正?(不修正可能会防盗链功能)`, '提示', {
125-
confirmButtonText: '确定',
126-
cancelButtonText: '取消',
127-
type: 'warning',
128-
callback: action => {
129-
if (action === 'confirm') {
130-
data.value.frontDomain = origin;
131-
saveForm();
132-
}
133-
}
134-
});
135-
}
148+
fixDomain.value.flag = true;
149+
fixDomain.value.current = siteDomain;
150+
fixDomain.value.except = serverDomain;
151+
fixDomain.value.action = () => {
152+
data.value.domain = serverDomain;
153+
saveForm();
154+
fixDomain.value.flag = false;
155+
}
136156
}
157+
158+
// 校验前端域名
159+
let siteFrontDomain = data.value.frontDomain;
160+
let origin = window.location.origin;
161+
// 如果是前后端分离场景,但设置的前端域名不等于当前域名,则提示用户修改
162+
if (globalConfigStore.zfileConfig.baseUrl !== '' && siteFrontDomain !== origin) {
163+
fixFrontDomain.value.flag = true;
164+
fixFrontDomain.value.current = siteFrontDomain;
165+
fixFrontDomain.value.except = origin;
166+
fixFrontDomain.value.action = () => {
167+
data.value.frontDomain = origin;
168+
saveForm();
169+
fixFrontDomain.value.flag = false;
170+
}
171+
// 如果是前后端不分离场景,但设置的前端域名不为空,则提示用户修改
172+
} else if (globalConfigStore.zfileConfig.baseUrl === '' && !!siteFrontDomain) {
173+
fixFrontDomain.value.flag = true;
174+
fixFrontDomain.value.current = siteFrontDomain;
175+
fixFrontDomain.value.except = '';
176+
fixFrontDomain.value.action = () => {
177+
data.value.frontDomain = '';
178+
saveForm();
179+
fixFrontDomain.value.flag = false;
180+
}
181+
}
137182
}
138183
})
139184

0 commit comments

Comments
 (0)