mirror of
https://github.com/certd/certd.git
synced 2026-04-23 19:57:27 +08:00
perf: 增加系统设置,可以关闭自助注册功能
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { request } from "../service";
|
||||
|
||||
export type SysPublicSetting = {
|
||||
registerEnabled:boolean
|
||||
}
|
||||
|
||||
|
||||
export async function getSysPublicSettings(): Promise<SysPublicSetting> {
|
||||
return await request({
|
||||
url: "/basic/settings/public",
|
||||
method: "get"
|
||||
});
|
||||
}
|
||||
@@ -55,6 +55,16 @@ export const sysResources = [
|
||||
},
|
||||
path: "/sys/authority/user",
|
||||
component: "/sys/authority/user/index.vue"
|
||||
},
|
||||
{
|
||||
title: "系统设置",
|
||||
name: "settings",
|
||||
meta: {
|
||||
icon: "ion:settings-outline",
|
||||
permission: "sys:settings:view"
|
||||
},
|
||||
path: "/sys/settings",
|
||||
component: "/sys/settings/index.vue"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { defineStore } from "pinia";
|
||||
// @ts-ignore
|
||||
import { LocalStorage } from "/src/utils/util.storage";
|
||||
import { SysPublicSetting } from "/@/api/modules/api.basic";
|
||||
import * as basicApi from '/@/api/modules/api.basic'
|
||||
import _ from "lodash-es";
|
||||
// import { replaceStyleVariables } from "vite-plugin-theme/es/client";
|
||||
|
||||
// import { getThemeColors, generateColors } from "/src/../build/theme-colors";
|
||||
@@ -23,8 +26,10 @@ import { LocalStorage } from "/src/utils/util.storage";
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
interface SettingState {
|
||||
theme: any;
|
||||
sysPublic?: SysPublicSetting
|
||||
}
|
||||
|
||||
const SETTING_THEME_KEY = "SETTING_THEME";
|
||||
@@ -32,14 +37,24 @@ export const useSettingStore = defineStore({
|
||||
id: "app.setting",
|
||||
state: (): SettingState => ({
|
||||
// user info
|
||||
theme: null
|
||||
theme: null,
|
||||
sysPublic: {
|
||||
registerEnabled: false
|
||||
}
|
||||
}),
|
||||
getters: {
|
||||
getTheme(): any {
|
||||
return this.theme || LocalStorage.get(SETTING_THEME_KEY) || {};
|
||||
},
|
||||
getSysPublic():SysPublicSetting{
|
||||
return this.sysPublic
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async loadSysSettings(){
|
||||
const settings = await basicApi.getSysPublicSettings()
|
||||
_.merge(this.sysPublic,settings)
|
||||
},
|
||||
persistTheme() {
|
||||
LocalStorage.set(SETTING_THEME_KEY, this.getTheme);
|
||||
},
|
||||
@@ -58,6 +73,7 @@ export const useSettingStore = defineStore({
|
||||
},
|
||||
async init() {
|
||||
await this.setTheme(this.getTheme);
|
||||
await this.loadSysSettings()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { request } from "/@/api/service";
|
||||
const apiPrefix = "/sys/settings";
|
||||
const apiPrefix = "/user/settings";
|
||||
|
||||
export const SettingKeys = {
|
||||
Email: "email"
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
</a-form-item>
|
||||
|
||||
<a-form-item class="user-login-other">
|
||||
<router-link class="register" :to="{ name: 'register' }"> 注册 </router-link>
|
||||
<router-link v-if="sysPublicSettings.registerEnabled" class="register" :to="{ name: 'register' }"> 注册 </router-link>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
@@ -74,11 +74,13 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, reactive, ref, toRaw, computed } from "vue";
|
||||
import { useUserStore } from "/src/store/modules/user";
|
||||
import { useSettingStore } from "/@/store/modules/settings";
|
||||
export default defineComponent({
|
||||
name: "LoginPage",
|
||||
setup() {
|
||||
const loading = ref(false);
|
||||
const userStore = useUserStore();
|
||||
const settingStore = useSettingStore()
|
||||
const formRef = ref();
|
||||
const formState = reactive({
|
||||
username: "",
|
||||
@@ -165,6 +167,7 @@ export default defineComponent({
|
||||
function sendSmsCode() {
|
||||
//api.sendSmsCode();
|
||||
}
|
||||
const sysPublicSettings = settingStore.getSysPublic
|
||||
return {
|
||||
loading,
|
||||
formState,
|
||||
@@ -179,7 +182,8 @@ export default defineComponent({
|
||||
resetImageCode,
|
||||
smsTime,
|
||||
smsSendBtnDisabled,
|
||||
sendSmsCode
|
||||
sendSmsCode,
|
||||
sysPublicSettings
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -65,6 +65,7 @@ export default defineComponent({
|
||||
//处理过,无需再次处理
|
||||
return;
|
||||
}
|
||||
value.class="is-twig"
|
||||
if (value.children != null && value.children.length > 0) {
|
||||
return;
|
||||
}
|
||||
@@ -82,8 +83,13 @@ export default defineComponent({
|
||||
}
|
||||
// 所有的子节点都没有children
|
||||
parent.class = "is-twig"; // 连接叶子节点的末梢枝杈节点
|
||||
let i = 0
|
||||
for (const child of parent.children) {
|
||||
child.class = "is-leaf";
|
||||
if(i !== 0){
|
||||
child.class += " leaf-after";
|
||||
}
|
||||
i++
|
||||
}
|
||||
});
|
||||
return [
|
||||
@@ -129,21 +135,40 @@ export default defineComponent({
|
||||
|
||||
<style lang="less">
|
||||
.fs-permission-tree {
|
||||
.is-twig ul {
|
||||
display: flex;
|
||||
|
||||
.ant-tree-list-holder-inner{
|
||||
flex-direction: row !important;
|
||||
flex-wrap: wrap;
|
||||
.is-twig{
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.is-leaf {
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: 5px;
|
||||
//border-bottom: 1px solid #ddd;
|
||||
&::before {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&.leaf-after{
|
||||
.ant-tree-indent-unit{
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.node-title-pane {
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//.is-twig ul {
|
||||
// display: flex;
|
||||
// flex-wrap: wrap;
|
||||
//}
|
||||
.node-title-pane {
|
||||
display: flex;
|
||||
.node-title {
|
||||
width: 80px;
|
||||
width: 110px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
<fs-crud ref="crudRef" v-bind="crudBinding">
|
||||
<a-button v-permission="'sys:auth:per:add'" style="margin-left: 20px" @click="addHandle({})">
|
||||
<fs-icon :icon="ui.icons.add"></fs-icon>
|
||||
添加</a-button
|
||||
>
|
||||
<fs-permission-tree class="permission-tree" :tree="crudBinding.data" :checkable="false" :actions="permission" @add="addHandle" @edit="editHandle" @remove="removeHandle"></fs-permission-tree>
|
||||
添加
|
||||
</a-button>
|
||||
<fs-permission-tree class="permission-tree mt-10" :tree="crudBinding.data" :checkable="false" :actions="permission" @add="addHandle" @edit="editHandle" @remove="removeHandle"></fs-permission-tree>
|
||||
</fs-crud>
|
||||
</fs-page>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// @ts-ignore
|
||||
import { request } from "/@/api/service";
|
||||
const apiPrefix = "/sys/settings";
|
||||
|
||||
export const SettingKeys = {
|
||||
SysPublic: "sys.public",
|
||||
SysPrivate: "sys.private",
|
||||
|
||||
};
|
||||
export async function SettingsGet(key: string) {
|
||||
return await request({
|
||||
url: apiPrefix + "/get",
|
||||
method: "post",
|
||||
params: {
|
||||
key
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function SettingsSave(key: string,setting: any) {
|
||||
await request({
|
||||
url: apiPrefix + "/save",
|
||||
method: "post",
|
||||
data: {
|
||||
key,
|
||||
setting: JSON.stringify(setting),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export async function PublicSettingsSave(setting: any) {
|
||||
await request({
|
||||
url: apiPrefix + "/savePublicSettings",
|
||||
method: "post",
|
||||
data: setting
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<fs-page class="page-sys-settings">
|
||||
<template #header>
|
||||
<div class="title">系统设置</div>
|
||||
</template>
|
||||
<div class="sys-settings-form">
|
||||
<a-form :model="formState" name="basic" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }" autocomplete="off" @finish="onFinish" @finish-failed="onFinishFailed">
|
||||
<a-form-item label="开启自助注册" name="registerEnabled">
|
||||
<a-switch v-model:checked="formState.registerEnabled" />
|
||||
</a-form-item>
|
||||
<a-form-item :wrapper-col="{ offset: 8, span: 16 }">
|
||||
<a-button type="primary" html-type="submit">保存</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
</fs-page>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive } from "vue";
|
||||
import * as api from "./api";
|
||||
import { PublicSettingsSave, SettingKeys } from "./api";
|
||||
import { notification } from "ant-design-vue";
|
||||
import { useSettingStore } from "/@/store/modules/settings";
|
||||
|
||||
interface FormState {
|
||||
registerEnabled: boolean;
|
||||
|
||||
}
|
||||
|
||||
const formState = reactive<Partial<FormState>>({
|
||||
registerEnabled:false
|
||||
});
|
||||
|
||||
async function loadSysPublicSettings() {
|
||||
const data: any = await api.SettingsGet(SettingKeys.SysPublic);
|
||||
const setting = JSON.parse(data.setting);
|
||||
Object.assign(formState, setting);
|
||||
}
|
||||
|
||||
loadSysPublicSettings();
|
||||
const settingsStore= useSettingStore()
|
||||
const onFinish = async (form: any) => {
|
||||
console.log("Success:", form);
|
||||
await api.PublicSettingsSave(form);
|
||||
await settingsStore.loadSysSettings()
|
||||
notification.success({
|
||||
message: "保存成功"
|
||||
});
|
||||
};
|
||||
|
||||
const onFinishFailed = (errorInfo: any) => {
|
||||
// console.log("Failed:", errorInfo);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.page-sys-settings {
|
||||
.sys-settings-form {
|
||||
width: 500px;
|
||||
margin: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user