优化自定义服务器

This commit is contained in:
kuaifan 2022-01-11 10:12:51 +08:00
parent 1d20f529a0
commit e711220a66
12 changed files with 115 additions and 66 deletions

1
cmd
View File

@ -160,6 +160,7 @@ run_mysql() {
fi
docker cp $filename $container_name:/
run_exec mariadb "gunzip < /$inputname | mysql -u$username -p$password $database"
run_exec php "php artisan migrate"
judge "还原数据库"
fi
}

2
electron/build.js vendored
View File

@ -27,7 +27,7 @@ function startBuild(data, publish) {
origin: "./",
apiUrl: utils.formatUrl(data.url) + "api/",
}
fs.writeFileSync(electronDir + "/config.js", "window.systemInformation = " + JSON.stringify(systemInfo, null, 2), 'utf8');
fs.writeFileSync(electronDir + "/config.js", "window.systemInfo = " + JSON.stringify(systemInfo, null, 2), 'utf8');
fs.writeFileSync(nativeCachePath, utils.formatUrl(data.url));
fs.writeFileSync(devloadCachePath, "", 'utf8');
// index.html

View File

@ -34,7 +34,7 @@
</div>
<script type="text/javascript">
document.writeln("<script src=\'./js/app.js?v=" + window.systemInformation.version + "\'><\/script>");
document.writeln("<script src=\'./js/app.js?v=" + window.systemInfo.version + "\'><\/script>");
</script>
</body>

View File

@ -51,7 +51,8 @@
"files": [
"public/**/*",
"main.js",
"preload.js"
"preload.js",
"utils.js"
],
"mac": {
"icon": "../resources/assets/statics/public/images/logo-app.png",

2
electron/utils.js vendored
View File

@ -249,7 +249,7 @@ module.exports = {
*/
getDomain(weburl) {
let urlReg = /http(s)?:\/\/([^\/]+)/i;
let domain = weburl.match(urlReg);
let domain = (weburl + "").match(urlReg);
return ((domain != null && domain.length > 0) ? domain[2] : "");
},
}

View File

@ -19,6 +19,11 @@
"name": "HitoseaTask",
"id": "com.hitosea.task",
"url": "https://t.hitosea.com/"
},
{
"name": "Public DooTask",
"id": "com.dootask.public",
"url": "https://public/"
}
]
},

View File

@ -125,9 +125,9 @@ export default {
},
chackReleases() {
let hostName = window.location.hostname;
if (hostName == '127.0.0.1') {
hostName = "www.dootask.com"
let hostName = $A.getDomain(window.systemInfo.apiUrl);
if (hostName == "" || hostName == '127.0.0.1') {
hostName = "public"
}
if (this.$Electron) {
//
@ -147,7 +147,7 @@ export default {
if (!this.repoData) {
return;
}
let currentVersion = window.systemInformation.version;
let currentVersion = window.systemInfo.version;
let latestVersion = $A.leftDelete(this.releases.tag_name.toLowerCase(), "v")
if (this.compareVersion(latestVersion, currentVersion) === 1) {
//

View File

@ -2,6 +2,7 @@
* 基础函数
*/
(function (window, $, undefined) {
window.systemInfo = window.systemInfo || {};
/**
* =============================================================================
@ -794,7 +795,7 @@
};
}
if (this.rightExists(url, '.js')) {
script.src = url + "?hash=" + window.systemInformation.version;
script.src = url + "?hash=" + window.systemInfo.version;
} else {
script.src = url;
}
@ -850,7 +851,7 @@
}
script.rel = 'stylesheet';
if (this.rightExists(url, '.css')) {
script.href = url + "?hash=" + window.systemInformation.version;
script.href = url + "?hash=" + window.systemInfo.version;
} else {
script.href = url;
}
@ -928,6 +929,17 @@
return {'<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;'}[c];
});
},
/**
* 正则提取域名
* @param weburl
* @returns {string|string}
*/
getDomain(weburl) {
let urlReg = /http(s)?:\/\/([^\/]+)/i;
let domain = (weburl + "").match(urlReg);
return ((domain != null && domain.length > 0) ? domain[2] : "");
},
});
/**

View File

@ -22,8 +22,8 @@
str.substring(0, 1) === "/") {
return str;
}
if (window.systemInformation && typeof window.systemInformation.apiUrl === "string") {
str = window.systemInformation.apiUrl + str;
if (typeof window.systemInfo.apiUrl === "string") {
str = window.systemInfo.apiUrl + str;
} else {
str = window.location.origin + "/api/" + str;
}
@ -34,7 +34,7 @@
},
/**
* 服务地址
* 服务地址
* @param str
* @returns {string}
*/
@ -46,8 +46,8 @@
str.substring(0, 1) === "/") {
return str;
}
if (window.systemInformation && typeof window.systemInformation.origin === "string") {
str = window.systemInformation.origin + str;
if (typeof window.systemInfo.origin === "string") {
str = window.systemInfo.origin + str;
} else {
str = window.location.origin + "/" + str;
}

View File

@ -4,13 +4,13 @@
<div class="login-body">
<div class="login-logo"></div>
<div class="login-box">
<div class="login-title">Welcome Dootask</div>
<div class="login-title">Welcome {{welcomeTitle}}</div>
<div v-if="loginType=='reg'" class="login-subtitle">{{$L('输入您的信息以创建帐户')}}</div>
<div v-else class="login-subtitle">{{$L('输入您的凭证以访问您的帐户。')}}</div>
<div class="login-input">
<Input v-if="$Electron && cacheServerUrl" :value="cacheServerUrl" prefix="ios-globe-outline" size="large" readonly clearable @on-clear="onServerUrlClear"/>
<Input v-if="$Electron && cacheServerUrl" :value="cacheServerUrl" prefix="ios-globe-outline" size="large" readonly clearable @on-clear="clearServerUrl"/>
<Input v-model="email" prefix="ios-mail-outline" :placeholder="$L('输入您的电子邮件')" size="large" @on-enter="onLogin" @on-blur="onBlur" />
<Input v-model="password" prefix="ios-lock-outline" :placeholder="$L('输入您的密码')" type="password" size="large" @on-enter="onLogin" />
@ -43,7 +43,7 @@
</div>
</div>
<div v-if="$Electron" class="login-right-bottom">
<Button icon="ios-globe-outline" type="primary" @click="onServerUrlInput">{{$L('自定义服务器')}}</Button>
<Button icon="ios-globe-outline" type="primary" @click="inputServerUrl">{{$L('自定义服务器')}}</Button>
</div>
</div>
</template>
@ -56,6 +56,8 @@ export default {
return {
loadIng: 0,
welcomeTitle: window.systemInfo.title || "Dootask",
codeNeed: false,
codeUrl: $A.apiUrl('users/login/codeimg'),
@ -75,8 +77,10 @@ export default {
mounted() {
this.getDemoAccount();
//
if (!this.$Electron && this.cacheServerUrl) {
this.onServerUrlClear();
if (this.$Electron) {
this.chackServerUrl();
} else {
this.clearServerUrl();
}
},
deactivated() {
@ -109,6 +113,9 @@ export default {
},
methods: {
getDemoAccount() {
if (this.isNotServer()) {
return;
}
this.$store.dispatch("call", {
url: 'system/demo',
}).then(({data}) => {
@ -140,7 +147,7 @@ export default {
this.codeUrl = $A.apiUrl('users/login/codeimg?_=' + Math.random())
},
onServerUrlInput() {
inputServerUrl() {
$A.modalInput({
title: "自定义服务器",
value: this.cacheServerUrl,
@ -156,23 +163,44 @@ export default {
this.$store.dispatch("call", {
url: value + 'system/setting',
}).then(() => {
$A.setStorage("cacheServerUrl", value)
window.location.reload();
this.setServerUrl(value)
}).catch(({msg}) => {
$A.modalError(msg || "服务器地址无效", 301);
cb()
});
return;
}
$A.setStorage("cacheServerUrl", "")
window.location.reload();
this.clearServerUrl();
}
});
},
onServerUrlClear() {
$A.setStorage("cacheServerUrl", "")
window.location.reload();
chackServerUrl() {
return new Promise((resolve, reject) => {
if (this.isNotServer()) {
$A.messageWarning("请设置服务器")
this.inputServerUrl()
reject()
} else {
resolve()
}
})
},
setServerUrl(value) {
if (value != this.cacheServerUrl) {
$A.setStorage("cacheServerUrl", value)
window.location.reload();
}
},
clearServerUrl() {
this.setServerUrl("")
},
isNotServer() {
let apiHome = $A.getDomain(window.systemInfo.apiUrl)
return apiHome == "" || apiHome == "public"
},
onBlur() {
@ -197,44 +225,46 @@ export default {
},
onLogin() {
if (!this.email) {
return;
}
if (!this.password) {
return;
}
if (this.loginType == 'reg') {
if (this.password != this.password2) {
$A.noticeError("确认密码输入不一致");
this.chackServerUrl().then(() => {
if (!this.email) {
return;
}
}
this.loadIng++;
this.$store.dispatch("call", {
url: 'users/login',
data: {
type: this.loginType,
email: this.email,
password: this.password,
code: this.code,
invite: this.invite,
},
}).then(({data}) => {
this.loadIng--;
$A.setStorage("cacheLoginEmail", this.email)
this.$store.dispatch("handleClearCache", data).then(() => {
this.goNext1();
}).catch(() => {
this.goNext1();
});
}).catch(({data, msg}) => {
this.loadIng--;
$A.noticeError(msg);
if (data.code === 'need') {
this.reCode();
this.codeNeed = true;
if (!this.password) {
return;
}
});
if (this.loginType == 'reg') {
if (this.password != this.password2) {
$A.noticeError("确认密码输入不一致");
return;
}
}
this.loadIng++;
this.$store.dispatch("call", {
url: 'users/login',
data: {
type: this.loginType,
email: this.email,
password: this.password,
code: this.code,
invite: this.invite,
},
}).then(({data}) => {
this.loadIng--;
$A.setStorage("cacheLoginEmail", this.email)
this.$store.dispatch("handleClearCache", data).then(() => {
this.goNext1();
}).catch(() => {
this.goNext1();
});
}).catch(({data, msg}) => {
this.loadIng--;
$A.noticeError(msg);
if (data.code === 'need') {
this.reCode();
this.codeNeed = true;
}
});
})
},
goNext1() {

View File

@ -26,8 +26,8 @@ state.cacheProjectParameter = $A.getStorageArray("cacheProjectParameter");
// ServerUrl
state.cacheServerUrl = $A.getStorageString("cacheServerUrl")
if (state.cacheServerUrl && window.systemInformation) {
window.systemInformation.apiUrl = state.cacheServerUrl;
if (state.cacheServerUrl) {
window.systemInfo.apiUrl = state.cacheServerUrl;
}
// Ajax

View File

@ -17,7 +17,7 @@
<script src="{{ asset_main('js/scroll-into-view.min.js') }}"></script>
<script>
window.csrfToken = { csrfToken : "{{ csrf_token() }}" };
window.systemInformation = { version : "{{ $version }}", origin: window.location.origin + "/", apiUrl: null };
window.systemInfo = { title: "{{config('app.name', 'WebPage')}}", version : "{{ $version }}", origin: window.location.origin + "/", apiUrl: null };
</script>
</head>
<body>