Browse Source

change login member

master
godo 9 months ago
parent
commit
9004143660
  1. 5
      frontend/components.d.ts
  2. 6
      frontend/src/components/desktop/DesktopBackground.vue
  3. 129
      frontend/src/components/desktop/LockDesktop.vue
  4. 1
      frontend/src/components/setting/SetSystem.vue
  5. 109
      frontend/src/system/index.ts
  6. 2
      frontend/src/system/type/enum.ts

5
frontend/components.d.ts

@ -42,11 +42,9 @@ declare module 'vue' {
EditType: typeof import('./src/components/builtin/EditType.vue')['default']
ElBadge: typeof import('element-plus/es')['ElBadge']
ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard']
ElCarousel: typeof import('element-plus/es')['ElCarousel']
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElCol: typeof import('element-plus/es')['ElCol']
ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElDrawer: typeof import('element-plus/es')['ElDrawer']
ElEmpty: typeof import('element-plus/es')['ElEmpty']
@ -64,7 +62,6 @@ declare module 'vue' {
ElSpace: typeof import('element-plus/es')['ElSpace']
ElTable: typeof import('element-plus/es')['ElTable']
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
ElText: typeof import('element-plus/es')['ElText']
ElTooltip: typeof import('element-plus/es')['ElTooltip']
Error: typeof import('./src/components/taskbar/Error.vue')['default']
FileIcon: typeof import('./src/components/builtin/FileIcon.vue')['default']
@ -81,6 +78,8 @@ declare module 'vue' {
InstallMember: typeof import('./src/components/install/InstallMember.vue')['default']
InstallPerson: typeof import('./src/components/install/InstallPerson.vue')['default']
LockDesktop: typeof import('./src/components/desktop/LockDesktop.vue')['default']
LoginDeskop: typeof import('./src/components/desktop/LoginDeskop.vue')['default']
LoginDesktop: typeof import('./src/components/desktop/LoginDesktop.vue')['default']
Magnet: typeof import('./src/components/taskbar/Magnet.vue')['default']
MarkDown: typeof import('./src/components/builtin/MarkDown.vue')['default']
MenuBar: typeof import('./src/components/window/MenuBar.vue')['default']

6
frontend/src/components/desktop/DesktopBackground.vue

@ -18,7 +18,7 @@ import { onMounted, ref, watch } from "vue";
import { useSystem } from "@/system";
const rootState = useSystem()._rootState;
const backgroundType = ref("color");
const background = ref("#3A98CE");
const background:any = ref("#3A98CE");
const loaded = ref(false);
function imgload() {
@ -32,8 +32,8 @@ watch(rootState.options, (nv) => {
});
function refershBack(val: string | undefined) {
background.value = val || "#3A98CE";
if (background.value.startsWith("/image/")) {
console.log(background.value)
if (background.value || background.value.startsWith("/image/")) {
backgroundType.value = "image";
} else {
backgroundType.value = "color";

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

@ -1,31 +1,71 @@
<script lang="ts" setup>
import { ref } from "vue";
import { useSystem } from "@/system";
import { getSystemConfig, getClientId } from '@/system/config'
const sys = useSystem();
const loginCallback = sys._options.loginCallback;
const config = getSystemConfig();
const lockClassName = ref("screen-show");
const alertMsg = ref("");
function loginSuccess() {
// lockClassName.value = 'screen-hidean';
// setTimeout(() => {
// lockClassName.value = 'screen-hide';
// }, 500);
lockClassName.value = 'screen-hidean';
setTimeout(() => {
lockClassName.value = 'screen-hide';
}, 500);
}
const userName = ref(sys._options.login?.username || "admin");
const userPassword = ref(sys._options.login?.password || "");
const userName = ref('');
const userPassword = ref('');
onMounted(() => {
if (config.userType == 'person') {
userName.value = sys._options.login?.username || "admin"
userPassword.value = sys._options.login?.password || ""
} else {
userName.value = config.userInfo.username
userPassword.value = config.userInfo.password
}
});
async function onLogin() {
if (loginCallback) {
alertMsg.value = "等待确认";
const res = await loginCallback(userName.value, userPassword.value);
if (res) {
loginSuccess();
} else {
alertMsg.value = "密码错误";
alertMsg.value = "等待确认";
const res = await loginCallback(userName.value, userPassword.value);
if (res) {
loginSuccess();
} else {
alertMsg.value = "密码错误";
}
}
}
// if (config.userType == 'person') {
// if (loginCallback) {
// alertMsg.value = "";
// const res = await loginCallback(userName.value, userPassword.value);
// if (res) {
// loginSuccess();
// } else {
// alertMsg.value = "";
// }
// }
// } else {
// const serverUrl = config.userInfo.url + '/member/login'
// const res:any = await fetch(serverUrl, {
// method: "POST",
// body: JSON.stringify({
// username: userName.value,
// password: userPassword.value,
// clientId: getClientId(),
// }),
// });
// if(!res.ok){
// alertMsg.value = ""
// return
// }
// const jsondata = await res.json();
// if (jsondata.success) {
// loginSuccess();
// } else {
// alertMsg.value = jsondata.message
// }
// }
}
</script>
@ -33,60 +73,32 @@ async function onLogin() {
<div class="lockscreen" :class="lockClassName">
<!---->
<div class="login-box">
<span
class="ant-avatar ant-avatar-icon"
style="width: 128px; height: 128px; line-height: 128px; font-size: 64px"
>
<span class="ant-avatar ant-avatar-icon" style="width: 128px; height: 128px; line-height: 128px; font-size: 64px">
<span role="img" aria-label="user" class="anticon">
<svg
focusable="false"
width="1em"
fill="currentColor"
aria-hidden="true"
viewBox="64 64 896 896"
>
<svg focusable="false" width="1em" fill="currentColor" aria-hidden="true" viewBox="64 64 896 896">
<path
d="M858.5 763.6a374 374 0 00-80.6-119.5 375.63 375.63 0 00-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 00-80.6 119.5A371.7 371.7 0 00136 901.8a8 8 0 008 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 008-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"
/>
d="M858.5 763.6a374 374 0 00-80.6-119.5 375.63 375.63 0 00-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 00-80.6 119.5A371.7 371.7 0 00136 901.8a8 8 0 008 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 008-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z" />
</svg>
</span>
</span>
<div class="username">
<span class="ant-input-group">
<input
placeholder="请输入用户名"
autofocus
class="ant-input"
v-model="userName"
/>
<input placeholder="请输入用户名" autofocus class="ant-input" v-model="userName" />
</span>
</div>
<span>
<span class="ant-input-group">
<!---->
<input
v-if="sys._options.noPassword !== true"
placeholder="请输入登录密码"
type="password"
autofocus
class="ant-input"
v-model="userPassword"
/>
<input v-if="sys._options.noPassword !== true" placeholder="请输入登录密码" type="password" autofocus
class="ant-input" v-model="userPassword" />
<span class="ant-input-group-addon">
<button class="ant-btn-primary" type="button" @click="onLogin">
<!---->
<span class="anticon">
<svg
focusable="false"
width="1em"
height="1em"
fill="currentColor"
aria-hidden="true"
viewBox="64 64 896 896"
>
<svg focusable="false" width="1em" height="1em" fill="currentColor" aria-hidden="true"
viewBox="64 64 896 896">
<path
d="M869 487.8L491.2 159.9c-2.9-2.5-6.6-3.9-10.5-3.9h-88.5c-7.4 0-10.8 9.2-5.2 14l350.2 304H152c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h585.1L386.9 854c-5.6 4.9-2.2 14 5.2 14h91.5c1.9 0 3.8-.7 5.2-2L869 536.2a32.07 32.07 0 000-48.4z"
/>
d="M869 487.8L491.2 159.9c-2.9-2.5-6.6-3.9-10.5-3.9h-88.5c-7.4 0-10.8 9.2-5.2 14l350.2 304H152c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h585.1L386.9 854c-5.6 4.9-2.2 14 5.2 14h91.5c1.9 0 3.8-.7 5.2-2L869 536.2a32.07 32.07 0 000-48.4z" />
</svg>
</span>
</button>
@ -113,6 +125,7 @@ async function onLogin() {
background-color: rgba(25, 28, 34, 0.78);
-webkit-backdrop-filter: blur(7px);
backdrop-filter: blur(7px);
.login-box {
position: absolute;
top: 45%;
@ -122,12 +135,14 @@ async function onLogin() {
flex-direction: column;
justify-content: center;
align-items: center;
.ant-avatar {
text-align: center;
vertical-align: middle;
background: #ccc;
border-radius: 50%;
margin-bottom: 14px;
.anticon {
display: inline-block;
color: inherit;
@ -141,14 +156,17 @@ async function onLogin() {
-moz-osx-font-smoothing: grayscale;
}
}
.ant-input-group {
display: flex;
.ant-input {
padding: 6px 11px;
font-size: 16px;
outline: none;
border: none;
}
.ant-btn-primary {
color: #fff;
background: #1890ff;
@ -163,11 +181,13 @@ async function onLogin() {
transition: all 0.3s;
cursor: pointer;
}
.ant-btn-primary:hover {
color: #fff;
background: #40a9ff;
border-color: #40a9ff;
}
.ant-btn-primary:active {
color: #fff;
background: #096dd9;
@ -180,6 +200,7 @@ async function onLogin() {
margin-bottom: 14px;
}
}
.tip {
padding: 4px 0px;
font-size: 12px;
@ -190,16 +211,20 @@ async function onLogin() {
.screen-hidean {
animation: outan 0.5s forwards;
}
.screen-hide {
display: none;
}
@keyframes outan {
0% {
opacity: 1;
}
30% {
opacity: 0;
}
100% {
transform: translateY(-100%);
opacity: 0;

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

@ -251,6 +251,7 @@ async function saveUserInfo() {
if (saveData.userType == 'person') {
setSystemConfig(saveData);
notifySuccess("保存成功");
RestartApp();
return
}
if (!urlRegex.test(saveData.userInfo.url.trim())) {

109
frontend/src/system/index.ts

@ -22,9 +22,10 @@ import { Notify, NotifyConstructorOptions } from './notification/Notification';
import { Dialog } from './window/Dialog';
import { pick } from '../util/modash';
import { Tray, TrayOptions } from './menu/Tary';
import { getSystemConfig, getSystemKey, setSystemKey, setSystemConfig, clearSystemConfig, getFileUrl,fetchGet } from './config'
import { getSystemConfig, getSystemKey, setSystemKey, setSystemConfig, clearSystemConfig, getFileUrl, fetchGet, getClientId } from './config'
import { useUpgradeStore } from '@/stores/upgrade';
import { RestartApp } from '@/util/goutil';
import { notifyError, notifySuccess } from '@/util/msg';
export type OsPlugin = (system: System) => void;
export type FileOpener = {
@ -92,17 +93,17 @@ export class System {
private async initSystem() {
this._rootState.state = SystemStateEnum.opening;
this.fs = useOsFile(); // 初始化文件系统
initBuiltinApp(this);
initBuiltinApp(this);
initBuiltinFileOpener(this); // 注册内建文件打开器
await this.initSavedConfig(); // 初始化保存的配置
// 判断是否登录
this.isLogin();
await this.isLogin();
initEventListener(); // 初始化事件侦听
this.initBackground(); // 初始化壁纸
this.refershAppList();
setTimeout(() => {
const upgradeStore = useUpgradeStore();
upgradeStore.systemMessage()
@ -114,29 +115,85 @@ export class System {
/**
* @description:
*/
private isLogin() {
if (!this._options.login) {
this._rootState.state = SystemStateEnum.open;
return;
} else {
if (this._options.login.init?.()) {
private async isLogin() {
const config = getSystemConfig();
if (config.userType == 'person') {
if (!this._options.login) {
this._rootState.state = SystemStateEnum.open;
return;
} else {
if (this._options.login.init?.()) {
this._rootState.state = SystemStateEnum.open;
return;
}
this._rootState.state = SystemStateEnum.lock;
const tempCallBack = this._options.loginCallback;
if (!tempCallBack) {
throw new Error('没有设置登录回调函数');
}
this._options.loginCallback = async (username: string, password: string) => {
const res = await tempCallBack(username, password);
if (res) {
this._rootState.state = SystemStateEnum.open;
return true;
}
return false;
};
}
} else {
const userInfo = config.userInfo;
if (userInfo.url == '') {
return true;
}
const res = await fetchGet(`${userInfo.url}/member/islogin`);
if (!res.ok) {
notifyError('登录失败,请检查网络连接或重新登录');
return true;
}
const data = await res.json();
//console.log(data)
if (data.success) {
this._rootState.state = SystemStateEnum.open;
return true;
} else {
//return true;
this._rootState.state = SystemStateEnum.lock;
this._rootState.state = SystemStateEnum.lock;
const tempCallBack = this._options.loginCallback;
if (!tempCallBack) {
throw new Error('没有设置登录回调函数');
this._options.loginCallback = async (username: string, password: string) => {
const serverUrl = config.userInfo.url + '/member/login'
const res: any = await fetch(serverUrl, {
method: "POST",
body: JSON.stringify({
username: username,
password: password,
clientId: getClientId(),
}),
});
if (!res.ok) {
return false
}
const jsondata = await res.json();
if (jsondata.success) {
jsondata.data.url = config.userInfo.url
jsondata.data.password = password
config.userInfo = jsondata.data
setSystemConfig(config);
this._rootState.state = SystemStateEnum.open;
this.refershAppList()
return true
} else {
notifyError(jsondata.message)
return false
}
};
// //const tmpCallBack = this._options.authCallback;
// this._options.authCallback = async (username: string, password: string, captcha :string) => {
// //this._rootState.state = SystemStateEnum.open;
// return false;
// };
// return false;
}
this._options.loginCallback = async (username: string, password: string) => {
const res = await tempCallBack(username, password);
if (res) {
this._rootState.state = SystemStateEnum.open;
return true;
}
return false;
};
}
}
@ -159,12 +216,12 @@ export class System {
}
refershAppList() {
const system = useSystem();
if (!system) return;
const fileUrl = getFileUrl();
if (!fileUrl) return;
fetchGet(`${fileUrl}/desktop`).then(res => res.json()).then(res => {
if (res && res.code == 0) {
system._rootState.apps.splice(0, system._rootState.apps.length, ...res.data.apps);
@ -173,7 +230,7 @@ export class System {
})
}
initAppList() {
this.isReadyUpdateAppList = true;
nextTick(() => {

2
frontend/src/system/type/enum.ts

@ -2,5 +2,5 @@ export const enum SystemStateEnum {
close = 0,
opening = 1,
open = 2,
lock = 3,
lock = 3
}

Loading…
Cancel
Save