Browse Source

Merge branch 'master' of https://gitee.com/godoos/godoos

master
godo 7 months ago
parent
commit
cc6c8cbac9
  1. 2
      frontend/components.d.ts
  2. 6513
      frontend/pnpm-lock.yaml
  3. BIN
      frontend/public/image/login/GitHub.png
  4. BIN
      frontend/public/image/login/QQ.png
  5. BIN
      frontend/public/image/login/gitee.png
  6. BIN
      frontend/public/image/login/微信.png
  7. BIN
      frontend/public/image/login/新浪微博.png
  8. 413
      frontend/src/components/desktop/LockDesktop.vue
  9. 156
      frontend/src/components/setting/SetSystem.vue
  10. 12
      frontend/src/stores/login.ts
  11. 22
      frontend/src/system/index.ts
  12. 9
      frontend/src/system/router.ts
  13. 11
      frontend/src/system/type/type.ts

2
frontend/components.d.ts

@ -68,6 +68,7 @@ declare module 'vue' {
ElCarousel: typeof import('element-plus/es')['ElCarousel'] ElCarousel: typeof import('element-plus/es')['ElCarousel']
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem'] ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElCol: typeof import('element-plus/es')['ElCol'] ElCol: typeof import('element-plus/es')['ElCol']
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
ElContainer: typeof import('element-plus/es')['ElContainer'] ElContainer: typeof import('element-plus/es')['ElContainer']
ElDialog: typeof import('element-plus/es')['ElDialog'] ElDialog: typeof import('element-plus/es')['ElDialog']
ElDrawer: typeof import('element-plus/es')['ElDrawer'] ElDrawer: typeof import('element-plus/es')['ElDrawer']
@ -105,6 +106,7 @@ declare module 'vue' {
FilePwd: typeof import('./src/components/oa/FilePwd.vue')['default'] FilePwd: typeof import('./src/components/oa/FilePwd.vue')['default']
FileTree: typeof import('./src/components/builtin/FileTree.vue')['default'] FileTree: typeof import('./src/components/builtin/FileTree.vue')['default']
FileViewer: typeof import('./src/components/builtin/FileViewer.vue')['default'] FileViewer: typeof import('./src/components/builtin/FileViewer.vue')['default']
GithubNext: typeof import('./src/components/desktop/GithubNext.vue')['default']
IframeFile: typeof import('./src/components/window/IframeFile.vue')['default'] IframeFile: typeof import('./src/components/window/IframeFile.vue')['default']
ImageViewer: typeof import('./src/components/builtin/ImageViewer.vue')['default'] ImageViewer: typeof import('./src/components/builtin/ImageViewer.vue')['default']
Install: typeof import('./src/components/install/Install.vue')['default'] Install: typeof import('./src/components/install/Install.vue')['default']

6513
frontend/pnpm-lock.yaml

File diff suppressed because it is too large

BIN
frontend/public/image/login/GitHub.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
frontend/public/image/login/QQ.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
frontend/public/image/login/gitee.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
frontend/public/image/login/微信.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
frontend/public/image/login/新浪微博.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

413
frontend/src/components/desktop/LockDesktop.vue

@ -1,12 +1,25 @@
<template> <template>
<div class="lockscreen" :class="lockClassName"> <div
<el-card class="login-box" shadow="never"> class="lockscreen"
:class="lockClassName"
>
<el-card
class="login-box"
shadow="never"
>
<div class="avatar-container"> <div class="avatar-container">
<el-avatar size="large"> <el-avatar size="large">
<img src="/logo.png" alt="Logo" /> <img
src="/logo.png"
alt="Logo"
/>
</el-avatar> </el-avatar>
</div> </div>
<el-form v-if="!isRegisterMode" label-position="left" label-width="0px"> <el-form
v-if="!isRegisterMode"
label-position="left"
label-width="0px"
>
<el-form-item> <el-form-item>
<el-input <el-input
v-model="userName" v-model="userName"
@ -25,13 +38,90 @@
@keyup.enter="onLogin" @keyup.enter="onLogin"
></el-input> ></el-input>
</el-form-item> </el-form-item>
<el-button type="primary" @click="onLogin">登录</el-button> <el-button
<div class="actions" v-if="config.userType === 'member'"> type="primary"
<a href="#" @click.prevent="toggleRegister">注册新用户</a> @click="onLogin"
<a href="#" @click.prevent="toggleUserSwitch">切换角色</a> >登录</el-button
>
<div class="divider">
<span>第三方登录</span>
</div>
<div class="third-party-login">
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/微信.png"
@click="onThirdPartyLogin('wechat')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/QQ.png"
@click="onThirdPartyLogin('qq')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/新浪微博.png"
@click="onThirdPartyLogin('sina')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/GitHub.png"
@click="onThirdPartyLogin('github')"
/>
<img
style="
width: 25px;
height: 25px;
cursor: pointer;
color: #409eff;
"
src="../../../public/image/login/gitee.png"
@click="onThirdPartyLogin('gitee')"
/>
</div>
<div
class="actions"
v-if="config.userType === 'member'"
>
<a
href="#"
@click.prevent="toggleRegister"
>注册新用户</a
>
<a
href="#"
@click.prevent="toggleUserSwitch"
>切换角色</a
>
</div> </div>
</el-form> </el-form>
<el-form v-else label-position="left" label-width="0px" :model="regForm" ref="regFormRef" :rules="rules"> <el-form
v-else
label-position="left"
label-width="0px"
:model="regForm"
ref="regFormRef"
:rules="rules"
>
<el-form-item prop="username"> <el-form-item prop="username">
<el-input <el-input
v-model="regForm.username" v-model="regForm.username"
@ -78,9 +168,17 @@
prefix-icon="Lock" prefix-icon="Lock"
></el-input> ></el-input>
</el-form-item> </el-form-item>
<el-button type="primary" @click="onRegister">注册</el-button> <el-button
type="primary"
@click="onRegister"
>注册</el-button
>
<div class="actions"> <div class="actions">
<a href="#" @click.prevent="toggleRegister">返回登录</a> <a
href="#"
@click.prevent="toggleRegister"
>返回登录</a
>
</div> </div>
</el-form> </el-form>
</el-card> </el-card>
@ -88,130 +186,272 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, onMounted } from 'vue'; import { useLoginStore } from "@/stores/login";
import { useSystem } from '@/system'; import { useSystem } from "@/system";
import { getSystemConfig, setSystemConfig } from '@/system/config'; import { getSystemConfig, setSystemConfig } from "@/system/config";
import { notifyError } from '@/util/msg'; import router from "@/system/router";
import { RestartApp } from '@/util/goutil'; import { RestartApp } from "@/util/goutil";
import { notifyError } from "@/util/msg";
import { onMounted, ref } from "vue";
const store = useLoginStore();
const sys = useSystem(); const sys = useSystem();
const loginCallback = sys._options.loginCallback; const loginCallback = sys._options.loginCallback;
const config = getSystemConfig(); const config = getSystemConfig();
const lockClassName = ref('screen-show'); const lockClassName = ref("screen-show");
const isRegisterMode = ref(false); const isRegisterMode = ref(false);
function loginSuccess() { function loginSuccess() {
lockClassName.value = 'screen-hidean'; lockClassName.value = "screen-hidean";
setTimeout(() => { setTimeout(() => {
lockClassName.value = 'screen-hide'; lockClassName.value = "screen-hide";
}, 500); }, 500);
} }
const userName = ref(''); const userName = ref("");
const userPassword = ref(''); const userPassword = ref("");
onMounted(() => { onMounted(() => {
if (config.userType === 'person') { if (config.userType === "person") {
userName.value = sys._options.login?.username || 'admin'; userName.value = sys._options.login?.username || "admin";
userPassword.value = sys._options.login?.password || ''; userPassword.value = sys._options.login?.password || "";
} else { } else {
userName.value = config.userInfo.username; userName.value = config.userInfo.username;
userPassword.value = config.userInfo.password; userPassword.value = config.userInfo.password;
} }
}); });
async function onLogin() { watch(
() => router.currentRoute.value.query.code,
() => {
onLogin();
}
);
const onLogin = async () => {
localStorage.removeItem("godoosClientId"); localStorage.removeItem("godoosClientId");
if (loginCallback) { if (loginCallback) {
const res = await loginCallback(userName.value, userPassword.value); const platform = store.ThirdPartyPlatform;
const code = router.currentRoute.value.query.code as string;
// 使
const platformCodeMap: Record<string, string> = {
github: "github_code",
gitee: "gitee_code",
wechat: "wechat_code",
qq: "qq_code",
};
//
const codeParam = platform ? platformCodeMap[platform] : null;
let res;
if (codeParam) {
//
const returnedState = router.currentRoute.value.query
.state as string;
if (returnedState !== store.State) {
notifyError("登录失败,请重试");
return;
}
res = await loginCallback(userName.value, userPassword.value, {
[codeParam]: code,
});
} else {
//
res = await loginCallback(userName.value, userPassword.value);
}
if (res) { if (res) {
store.ThirdPartyPlatform = null;
loginSuccess(); loginSuccess();
} else {
notifyError("登录失败,请重试");
} }
} }
} };
function toggleRegister() { const toggleRegister = () => {
isRegisterMode.value = !isRegisterMode.value; isRegisterMode.value = !isRegisterMode.value;
} };
function toggleUserSwitch() { const toggleUserSwitch = () => {
config.userType = 'person' config.userType = "person";
setSystemConfig(config); setSystemConfig(config);
RestartApp(); RestartApp();
} };
const regForm = ref({ const regForm = ref({
username: '', username: "",
password: '', password: "",
confirmPassword: '', confirmPassword: "",
email: '', email: "",
phone: '', phone: "",
nickname: '', nickname: "",
}) });
const regFormRef: any = ref(null); const regFormRef: any = ref(null);
const rules = { const rules = {
username: [ username: [
{ required: true, message: '用户名不能为空', trigger: 'blur' }, { required: true, message: "用户名不能为空", trigger: "blur" },
{ min: 3, max: 20, message: '用户名长度应在3到20个字符之间', trigger: 'blur' } {
min: 3,
max: 20,
message: "用户名长度应在3到20个字符之间",
trigger: "blur",
},
], ],
password: [ password: [
{ required: true, message: '密码不能为空', trigger: 'blur' }, { required: true, message: "密码不能为空", trigger: "blur" },
{ min: 6, message: '密码长度不能小于6位', trigger: 'blur' } { min: 6, message: "密码长度不能小于6位", trigger: "blur" },
], ],
confirmPassword: [ confirmPassword: [
{ required: true, message: '请再次输入密码', trigger: 'blur' }, { required: true, message: "请再次输入密码", trigger: "blur" },
{ validator: (rule:any, value:any, callback:any) => { {
console.log(rule) validator: (rule: any, value: any, callback: any) => {
if (value === '') { console.log(rule);
callback(new Error('请再次输入密码')); if (value === "") {
callback(new Error("请再次输入密码"));
} else if (value !== regForm.value.password) { } else if (value !== regForm.value.password) {
callback(new Error('两次输入的密码不一致')); callback(new Error("两次输入的密码不一致"));
} else { } else {
callback(); callback();
} }
}, trigger: 'blur' } },
trigger: "blur",
},
], ],
email: [ email: [
{ required: true, message: '邮箱不能为空', trigger: 'blur' }, { required: true, message: "邮箱不能为空", trigger: "blur" },
{ type: 'email', message: '请输入有效的邮箱地址', trigger: ['blur', 'change'] } {
type: "email",
message: "请输入有效的邮箱地址",
trigger: ["blur", "change"],
},
], ],
phone: [ phone: [
{ required: true, message: '手机号不能为空', trigger: 'blur' }, { required: true, message: "手机号不能为空", trigger: "blur" },
{ pattern: /^1[3-9]\d{9}$/, message: '请输入有效的手机号', trigger: 'blur' } {
pattern: /^1[3-9]\d{9}$/,
message: "请输入有效的手机号",
trigger: "blur",
},
], ],
nickname: [ nickname: [
{ required: true, message: '昵称不能为空', trigger: 'blur' }, { required: true, message: "昵称不能为空", trigger: "blur" },
{ min: 2, max: 20, message: '昵称长度应在2到20个字符之间', trigger: 'blur' } {
] min: 2,
max: 20,
message: "昵称长度应在2到20个字符之间",
trigger: "blur",
},
],
}; };
async function onRegister() { const onRegister = async () => {
try { try {
await regFormRef.value.validate(); await regFormRef.value.validate();
const save = toRaw(regForm.value); const save = toRaw(regForm.value);
const userInfo = config.userInfo; const userInfo = config.userInfo;
const comp = await fetch(userInfo.url + '/member/register', { const comp = await fetch(userInfo.url + "/member/register", {
method: 'POST', method: "POST",
body: JSON.stringify(save), body: JSON.stringify(save),
}); });
if (!comp.ok) { if (!comp.ok) {
notifyError('网络错误,注册失败'); notifyError("网络错误,注册失败");
return return;
} }
const res = await comp.json(); const res = await comp.json();
if (res.success) { if (res.success) {
notifyError('注册成功'); notifyError("注册成功");
toggleRegister(); toggleRegister();
} else { } else {
notifyError(res.message); notifyError(res.message);
return return;
} }
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
};
const onThirdPartyLogin = async (platform: string) => {
let loginFunction: (() => Promise<boolean>) | undefined;
//
store.ThirdPartyPlatform = platform;
switch (platform) {
case "github":
// GitHub
loginFunction = async function () {
return await authWithGithub();
};
break;
case "wechat":
loginFunction = async function () {
return await authWithWechat();
};
break;
case "qq":
loginFunction = async function () {
return await authWithQQ();
};
break;
case "sina":
loginFunction = async function () {
return await authWithSina();
};
break;
case "gitee":
loginFunction = async function () {
return await authWithGithub();
};
break;
default:
notifyError("不支持的第三方登录平台");
return;
}
if (loginFunction) {
const success = await loginFunction();
if (success) {
loginSuccess();
} else {
notifyError("登录失败");
}
}
};
const authWithGithub = async (): Promise<boolean> => {
// stateCSRF,使
const state = Date.now() + Math.random().toString(36).substring(2, 15);
//
store.State = state;
const url = config.userInfo.url + "/github/authorize?state=" + state;
const res: any = await fetch(url, {
method: "POST",
body: JSON.stringify({
state: state,
}),
});
if (!res.ok) {
return false;
} }
const data = await res.json();
console.log(data.data.url);
window.location.href = data.data.url;
return true;
};
const authWithWechat = (): boolean | PromiseLike<boolean> => {
throw new Error("Function not implemented.");
};
const authWithQQ = (): boolean | PromiseLike<boolean> => {
throw new Error("Function not implemented.");
};
const authWithSina = (): boolean | PromiseLike<boolean> => {
throw new Error("Function not implemented.");
};
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@ -295,6 +535,47 @@ async function onRegister() {
.screen-hide { .screen-hide {
display: none; display: none;
} }
.third-party-login {
margin-top: 10px;
display: flex;
justify-content: center;
gap: 15px;
el-icon {
font-size: 24px;
cursor: pointer;
transition: color 0.3s ease;
&:hover {
color: #409eff;
}
}
}
.divider {
display: flex;
align-items: center;
text-align: center;
margin: 20px 0;
color: #999;
font-size: 14px;
&::before,
&::after {
content: "";
flex: 1;
border-bottom: 1px solid #ddd;
}
&::before {
margin-right: 0.25em;
}
&::after {
margin-left: 0.25em;
}
}
} }
@keyframes outan { @keyframes outan {

156
frontend/src/components/setting/SetSystem.vue

@ -2,34 +2,59 @@
<div class="container"> <div class="container">
<div class="nav"> <div class="nav">
<ul> <ul>
<li v-for="(item, index) in items" :key="index" @click="selectItem(index)" <li
:class="{ active: index === activeIndex }"> v-for="(item, index) in items"
:key="index"
@click="selectItem(index)"
:class="{ active: index === activeIndex }"
>
{{ item }} {{ item }}
</li> </li>
</ul> </ul>
</div> </div>
<div class="setting"> <div class="setting">
<div v-if="1 === activeIndex"> <div v-if="1 === activeIndex">
<div class="setting-item" style="margin-top: 60px"> <div
class="setting-item"
style="margin-top: 60px"
>
<label>存储方式</label> <label>存储方式</label>
<el-select v-model="config.storeType"> <el-select v-model="config.storeType">
<el-option v-for="(item, key) in storeList" :key="key" :label="item.title" :value="item.value" /> <el-option
v-for="(item, key) in storeList"
:key="key"
:label="item.title"
:value="item.value"
/>
</el-select> </el-select>
</div> </div>
<div class="setting-item" v-if="config.storeType === 'local'"> <div
class="setting-item"
v-if="config.storeType === 'local'"
>
<label>存储地址</label> <label>存储地址</label>
<el-input v-model="config.storePath" @click="selectFile()" placeholder="可为空,为空则取系统默认存储地址" /> <el-input
v-model="config.storePath"
@click="selectFile()"
placeholder="可为空,为空则取系统默认存储地址"
/>
</div> </div>
<template v-if="config.storeType === 'net'"> <template v-if="config.storeType === 'net'">
<div class="setting-item"> <div class="setting-item">
<label>服务器地址</label> <label>服务器地址</label>
<el-input v-model="config.storenet.url" placeholder="http://192.168.1.16:56780 不要加斜杠" /> <el-input
v-model="config.storenet.url"
placeholder="http://192.168.1.16:56780 不要加斜杠"
/>
</div> </div>
</template> </template>
<template v-if="config.storeType === 'webdav'"> <template v-if="config.storeType === 'webdav'">
<div class="setting-item"> <div class="setting-item">
<label>服务器地址</label> <label>服务器地址</label>
<el-input v-model="config.webdavClient.url" placeholder="https://godoos.com/webdav 不要加斜杠" /> <el-input
v-model="config.webdavClient.url"
placeholder="https://godoos.com/webdav 不要加斜杠"
/>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>登陆用户名</label> <label>登陆用户名</label>
@ -37,13 +62,19 @@
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>登陆密码</label> <label>登陆密码</label>
<el-input v-model="config.webdavClient.password" type="password" /> <el-input
v-model="config.webdavClient.password"
type="password"
/>
</div> </div>
</template> </template>
<div class="setting-item"> <div class="setting-item">
<label></label> <label></label>
<el-button @click="submitOsInfo" type="primary"> <el-button
@click="submitOsInfo"
type="primary"
>
{{ t("confirm") }} {{ t("confirm") }}
</el-button> </el-button>
</div> </div>
@ -55,46 +86,85 @@
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label></label> <label></label>
<el-button @click="exportBackup" type="primary"> 导出 </el-button> <el-button
@click="exportBackup"
type="primary"
>
导出
</el-button>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<h1 class="setting-title">还原</h1> <h1 class="setting-title">还原</h1>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label></label> <label></label>
<el-button @click="selectZipfile" type="primary"> 导入 </el-button> <el-button
<input type="file" accept=".zip" style="display: none" ref="zipFileInput" /> @click="selectZipfile"
type="primary"
>
导入
</el-button>
<input
type="file"
accept=".zip"
style="display: none"
ref="zipFileInput"
/>
</div> </div>
</div> </div>
<div v-if="0 === activeIndex"> <div v-if="0 === activeIndex">
<div class="setting-item" style="margin-top: 60px"> <div
class="setting-item"
style="margin-top: 60px"
>
<label>用户角色</label> <label>用户角色</label>
<el-select v-model="config.userType"> <el-select v-model="config.userType">
<el-option v-for="(item, key) in userTypes" :key="key" :label="item.title" :value="item.value" /> <el-option
v-for="(item, key) in userTypes"
:key="key"
:label="item.title"
:value="item.value"
/>
</el-select> </el-select>
</div> </div>
<template v-if="config.userType === 'member'"> <template v-if="config.userType === 'member'">
<div class="setting-item"> <div class="setting-item">
<label>服务器地址</label> <label>服务器地址</label>
<el-input v-model="config.userInfo.url" placeholder="网址或域名,例子:https://godoos.com 不要加斜杠" /> <el-input
v-model="config.userInfo.url"
placeholder="网址或域名,例子:https://godoos.com 不要加斜杠"
/>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>用户名</label> <label>用户名</label>
<el-input v-model="config.userInfo.username" placeholder="登录用户名" /> <el-input
v-model="config.userInfo.username"
placeholder="登录用户名"
/>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>密码</label> <label>密码</label>
<el-input v-model="config.userInfo.password" type="password" placeholder="登录密码" /> <el-input
v-model="config.userInfo.password"
type="password"
placeholder="登录密码"
/>
</div> </div>
</template> </template>
<div class="setting-item"> <div class="setting-item">
<label></label> <label></label>
<el-button @click="saveUserInfo" type="primary"> <el-button
@click="saveUserInfo"
type="primary"
>
{{ t("confirm") }} {{ t("confirm") }}
</el-button> </el-button>
</div> </div>
</div> </div>
<div v-if="3 === activeIndex" class="setting-area"> <div
v-if="3 === activeIndex"
class="setting-area"
>
<SetFilePwd v-if="config.userType === 'person'"></SetFilePwd> <SetFilePwd v-if="config.userType === 'person'"></SetFilePwd>
</div> </div>
</div> </div>
@ -102,13 +172,17 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { inject, ref } from "vue";
import { Dialog, join, System, t } from "@/system"; import { Dialog, join, System, t } from "@/system";
import JSZip from "jszip"; import {
import FileSaver from "file-saver"; getClientId,
import { getSystemConfig, setSystemConfig,getClientId } from "@/system/config"; getSystemConfig,
setSystemConfig,
} from "@/system/config";
import { OpenDirDialog, RestartApp } from "@/util/goutil"; import { OpenDirDialog, RestartApp } from "@/util/goutil";
import { notifyError, notifySuccess } from "@/util/msg"; import { notifyError, notifySuccess } from "@/util/msg";
import FileSaver from "file-saver";
import JSZip from "jszip";
import { inject, ref } from "vue";
const config = ref(getSystemConfig()); const config = ref(getSystemConfig());
const sys = inject<System>("system")!; const sys = inject<System>("system")!;
let zipFile: File | undefined = undefined; let zipFile: File | undefined = undefined;
@ -144,7 +218,7 @@ const userTypes = [
title: "企业用户", title: "企业用户",
value: "member", value: "member",
}, },
] ];
const activeIndex = ref(0); const activeIndex = ref(0);
const selectItem = (index: number) => { const selectItem = (index: number) => {
@ -221,7 +295,10 @@ function submitOsInfo() {
}); });
return; return;
} }
if (saveData.webdavClient.username === "" || saveData.webdavClient.password === "") { if (
saveData.webdavClient.username === "" ||
saveData.webdavClient.password === ""
) {
Dialog.showMessageBox({ Dialog.showMessageBox({
message: "用户名或密码不能为空", message: "用户名或密码不能为空",
type: "error", type: "error",
@ -251,11 +328,11 @@ function submitOsInfo() {
} }
async function saveUserInfo() { async function saveUserInfo() {
const saveData = toRaw(config.value); const saveData = toRaw(config.value);
if (saveData.userType == 'person') { if (saveData.userType == "person") {
setSystemConfig(saveData); setSystemConfig(saveData);
notifySuccess("保存成功"); notifySuccess("保存成功");
RestartApp(); RestartApp();
return return;
} }
if (!urlRegex.test(saveData.userInfo.url.trim())) { if (!urlRegex.test(saveData.userInfo.url.trim())) {
Dialog.showMessageBox({ Dialog.showMessageBox({
@ -264,15 +341,18 @@ async function saveUserInfo() {
}); });
return; return;
} }
if (saveData.userInfo.username === "" || saveData.userInfo.password === "") { if (
saveData.userInfo.username === "" ||
saveData.userInfo.password === ""
) {
Dialog.showMessageBox({ Dialog.showMessageBox({
message: "用户名或密码不能为空", message: "用户名或密码不能为空",
type: "error", type: "error",
}); });
return; return;
} }
const password = saveData.userInfo.password const password = saveData.userInfo.password;
const serverUrl = saveData.userInfo.url + '/member/login' const serverUrl = saveData.userInfo.url + "/member/login";
const res = await fetch(serverUrl, { const res = await fetch(serverUrl, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -284,20 +364,20 @@ async function saveUserInfo() {
if (res.status === 200) { if (res.status === 200) {
const data = await res.json(); const data = await res.json();
if (data.success) { if (data.success) {
data.data.url = saveData.userInfo.url data.data.url = saveData.userInfo.url;
data.data.password = password data.data.password = password;
saveData.userInfo = data.data saveData.userInfo = data.data;
setSystemConfig(saveData); setSystemConfig(saveData);
notifySuccess("登录成功"); notifySuccess("登录成功");
RestartApp(); RestartApp();
return return;
} else { } else {
notifyError(data.message) notifyError(data.message);
} }
} else { } else {
notifyError("登录失败"); notifyError("登录失败");
} }
return return;
} }
async function exportBackup() { async function exportBackup() {
const { setProgress } = Dialog.showProcessDialog({ const { setProgress } = Dialog.showProcessDialog({
@ -401,8 +481,6 @@ async function importBackup(path = "") {
}, 100); }, 100);
} }
} }
</script> </script>
<style scoped> <style scoped>
@import "./setStyle.css"; @import "./setStyle.css";

12
frontend/src/stores/login.ts

@ -0,0 +1,12 @@
import { defineStore } from 'pinia';
export const useLoginStore = defineStore("login", () => {
// 第三方登录方式
const ThirdPartyPlatform = ref<string | null>(null);
const State = ref<string | null>(null);
return {
ThirdPartyPlatform,
State
};
});

22
frontend/src/system/index.ts

@ -14,9 +14,9 @@ import {
} from './type/type'; } from './type/type';
import { BrowserWindow, BrowserWindowOption } from './window/BrowserWindow'; import { BrowserWindow, BrowserWindowOption } from './window/BrowserWindow';
import { useUpgradeStore } from '@/stores/upgrade';
import { useAssistantStore } from '@/stores/assistant'; import { useAssistantStore } from '@/stores/assistant';
import { useModelStore } from "@/stores/model.ts"; import { useModelStore } from "@/stores/model.ts";
import { useUpgradeStore } from '@/stores/upgrade';
import { RestartApp } from '@/util/goutil'; import { RestartApp } from '@/util/goutil';
import { notifyError } from '@/util/msg'; import { notifyError } from '@/util/msg';
import { isShareFile } from '@/util/sharePath'; import { isShareFile } from '@/util/sharePath';
@ -134,6 +134,7 @@ export class System {
*/ */
private async isLogin() { private async isLogin() {
const config = getSystemConfig(); const config = getSystemConfig();
if (config.userType == 'person') { if (config.userType == 'person') {
if (!this._options.login) { if (!this._options.login) {
this._rootState.state = SystemStateEnum.open; this._rootState.state = SystemStateEnum.open;
@ -159,6 +160,7 @@ export class System {
}; };
} }
} else { } else {
// 非个人用户
const userInfo = config.userInfo; const userInfo = config.userInfo;
if (userInfo.url == '') { if (userInfo.url == '') {
return true; return true;
@ -171,25 +173,35 @@ export class System {
const data = await res.json(); const data = await res.json();
//console.log(data) //console.log(data)
if (data.success) { if (data.success) {
// 登录成功
this._rootState.state = SystemStateEnum.open; this._rootState.state = SystemStateEnum.open;
return true; return true;
} else { } else {
// 登录失败
//return true; //return true;
this._rootState.state = SystemStateEnum.lock; this._rootState.state = SystemStateEnum.lock;
// 登录回调
this._options.loginCallback = async (username: string, password: string) => { this._options.loginCallback = async (
username: string, password: string, loginCode?: {
github_code?: string,
gitee_code?: string
}
) => {
const serverUrl = config.userInfo.url + '/member/login' const serverUrl = config.userInfo.url + '/member/login'
const res: any = await fetch(serverUrl, { const res: any = await fetch(serverUrl, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
username: username, username: username,
password: password, password: password,
github_code: loginCode?.github_code,
gitee_code: loginCode?.gitee_code,
clientId: getClientId(), clientId: getClientId(),
}), }),
}); });
if (!res.ok) { if (!res.ok) {
return false return false
} }
const jsondata = await res.json(); const jsondata = await res.json();
if (jsondata.success) { if (jsondata.success) {
jsondata.data.url = config.userInfo.url jsondata.data.url = config.userInfo.url
@ -198,12 +210,16 @@ export class System {
setSystemConfig(config); setSystemConfig(config);
this._rootState.state = SystemStateEnum.open; this._rootState.state = SystemStateEnum.open;
this.refershAppList() this.refershAppList()
window.location.href = "/";
return true return true
} else { } else {
notifyError(jsondata.message) notifyError(jsondata.message)
return false return false
} }
}; };
// //const tmpCallBack = this._options.authCallback; // //const tmpCallBack = this._options.authCallback;
// this._options.authCallback = async (username: string, password: string, captcha :string) => { // this._options.authCallback = async (username: string, password: string, captcha :string) => {
// //this._rootState.state = SystemStateEnum.open; // //this._rootState.state = SystemStateEnum.open;

9
frontend/src/system/router.ts

@ -1,4 +1,4 @@
import { createWebHistory, createRouter } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
const routes = [ const routes = [
// { // {
@ -10,8 +10,13 @@ const routes = [
// name: "install", // name: "install",
// component: () => import('../views/install/install.vue') // 关于我们组件 // component: () => import('../views/install/install.vue') // 关于我们组件
// }, // },
// {
// path: "/login/github/next",
// name: "login-github",
// component: () => import("../components/desktop/GithubNext.vue"),
// },
{ {
path: '/:pathMatch(.*)*', path: "/:pathMatch(.*)*",
name: "not-found", name: "not-found",
component: () => import('../components/window/NotFound.vue') component: () => import('../components/window/NotFound.vue')
} }

11
frontend/src/system/type/type.ts

@ -1,5 +1,5 @@
import { BrowserWindowOption } from '../window/BrowserWindow';
import { MenuItem, MenuItemConstructorOptions } from '../menu/MenuItem'; import { MenuItem, MenuItemConstructorOptions } from '../menu/MenuItem';
import { BrowserWindowOption } from '../window/BrowserWindow';
export type BuiltinFeature = export type BuiltinFeature =
| 'MyComputer' | 'MyComputer'
| 'AppStore' | 'AppStore'
@ -56,7 +56,14 @@ export interface SystemOptionsCertainly {
}; };
contextMenus?: Array<MenuItemConstructorOptions | MenuItem>; contextMenus?: Array<MenuItemConstructorOptions | MenuItem>;
noPassword?: boolean; noPassword?: boolean;
loginCallback?: (username: string, password: string) => Promise<boolean>; loginCallback?: (
username: string,
password: string,
loginCode?: {
github_code?: string,
gitee_code?: string
}
) => Promise<boolean>;
} }
export type SystemOptions = SystemOptionsCertainly & { export type SystemOptions = SystemOptionsCertainly & {
[key: string]: SafeAny; [key: string]: SafeAny;

Loading…
Cancel
Save