mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-18 01:36:37 +08:00
refactor(projects): 代码优化
ISSUES CLOSED: \
This commit is contained in:
parent
8f6d6ce3cb
commit
d28b9039bb
@ -1,13 +1,13 @@
|
|||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { useAppStore, useThemeStore } from '@/store';
|
import { useAppStore, useThemeStore } from '@/store';
|
||||||
|
|
||||||
|
type LayoutMode = 'vertical' | 'horizontal';
|
||||||
type LayoutHeaderProps = Record<EnumType.ThemeLayoutMode, GlobalHeaderProps>;
|
type LayoutHeaderProps = Record<EnumType.ThemeLayoutMode, GlobalHeaderProps>;
|
||||||
|
|
||||||
export function useBasicLayout() {
|
export function useBasicLayout() {
|
||||||
const app = useAppStore();
|
const app = useAppStore();
|
||||||
const theme = useThemeStore();
|
const theme = useThemeStore();
|
||||||
|
|
||||||
type LayoutMode = 'vertical' | 'horizontal';
|
|
||||||
const mode = computed(() => {
|
const mode = computed(() => {
|
||||||
const vertical: LayoutMode = 'vertical';
|
const vertical: LayoutMode = 'vertical';
|
||||||
const horizontal: LayoutMode = 'horizontal';
|
const horizontal: LayoutMode = 'horizontal';
|
||||||
|
@ -3,7 +3,6 @@ export enum EnumUserRole {
|
|||||||
super = '超级管理员',
|
super = '超级管理员',
|
||||||
admin = '管理员',
|
admin = '管理员',
|
||||||
user = '普通用户'
|
user = '普通用户'
|
||||||
// custom = '自定义角色'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录模块 */
|
/** 登录模块 */
|
||||||
|
@ -31,5 +31,6 @@ export enum EnumDataType {
|
|||||||
date = '[object Date]',
|
date = '[object Date]',
|
||||||
regexp = '[object RegExp]',
|
regexp = '[object RegExp]',
|
||||||
set = '[object Set]',
|
set = '[object Set]',
|
||||||
map = '[object Map]'
|
map = '[object Map]',
|
||||||
|
file = '[object File]'
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
|
|||||||
|
|
||||||
ctx.fillStyle = randomColor(180, 230);
|
ctx.fillStyle = randomColor(180, 230);
|
||||||
ctx.fillRect(0, 0, width, height);
|
ctx.fillRect(0, 0, width, height);
|
||||||
|
|
||||||
for (let i = 0; i < 4; i += 1) {
|
for (let i = 0; i < 4; i += 1) {
|
||||||
const text = NUMBER_STRING[randomNum(0, NUMBER_STRING.length)];
|
const text = NUMBER_STRING[randomNum(0, NUMBER_STRING.length)];
|
||||||
imgCode += text;
|
imgCode += text;
|
||||||
@ -81,5 +82,6 @@ function draw(dom: HTMLCanvasElement, width: number, height: number) {
|
|||||||
ctx.fillStyle = randomColor(150, 200);
|
ctx.fillStyle = randomColor(150, 200);
|
||||||
ctx.fill();
|
ctx.fill();
|
||||||
}
|
}
|
||||||
|
|
||||||
return imgCode;
|
return imgCode;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import useCountDown from './useCountDown';
|
|||||||
export default function useSmsCode() {
|
export default function useSmsCode() {
|
||||||
const { loading, startLoading, endLoading } = useLoading();
|
const { loading, startLoading, endLoading } = useLoading();
|
||||||
const { counts, start, isCounting } = useCountDown(60);
|
const { counts, start, isCounting } = useCountDown(60);
|
||||||
|
|
||||||
const initLabel = '获取验证码';
|
const initLabel = '获取验证码';
|
||||||
const countingLabel = (second: number) => `${second}秒后重新获取`;
|
const countingLabel = (second: number) => `${second}秒后重新获取`;
|
||||||
const label = computed(() => {
|
const label = computed(() => {
|
||||||
@ -40,6 +41,7 @@ export default function useSmsCode() {
|
|||||||
async function getSmsCode(phone: string) {
|
async function getSmsCode(phone: string) {
|
||||||
const valid = isPhoneValid(phone);
|
const valid = isPhoneValid(phone);
|
||||||
if (!valid || loading.value) return;
|
if (!valid || loading.value) return;
|
||||||
|
|
||||||
startLoading();
|
startLoading();
|
||||||
const { data } = await fetchSmsCode(phone);
|
const { data } = await fetchSmsCode(phone);
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -13,10 +13,13 @@ export default function useReload() {
|
|||||||
async function handleReload(duration = 0) {
|
async function handleReload(duration = 0) {
|
||||||
setFalse();
|
setFalse();
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
|
if (duration > 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setTrue();
|
setTrue();
|
||||||
}, duration);
|
}, duration);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
reloadFlag,
|
reloadFlag,
|
||||||
|
@ -33,3 +33,6 @@ export function isSet(data: unknown) {
|
|||||||
export function isMap(data: unknown) {
|
export function isMap(data: unknown) {
|
||||||
return Object.prototype.toString.call(data) === EnumDataType.map;
|
return Object.prototype.toString.call(data) === EnumDataType.map;
|
||||||
}
|
}
|
||||||
|
export function isFile(data: unknown) {
|
||||||
|
return Object.prototype.toString.call(data) === EnumDataType.file;
|
||||||
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
import { EnumContentType } from '@/enum';
|
import { EnumContentType } from '@/enum';
|
||||||
import { isArray } from '../common';
|
import { isArray, isFile } from '../common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求数据的转换
|
* 请求数据的转换
|
||||||
@ -17,20 +17,35 @@ export async function transformRequestData(requestData: any, contentType?: strin
|
|||||||
}
|
}
|
||||||
// form-data类型转换
|
// form-data类型转换
|
||||||
if (contentType === EnumContentType.formData) {
|
if (contentType === EnumContentType.formData) {
|
||||||
const key = Object.keys(requestData)[0];
|
data = await handleFormData(requestData);
|
||||||
const file = requestData.data[key];
|
|
||||||
data = await transformFile(file, key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleFormData(data: Record<string, any>) {
|
||||||
|
const formData = new FormData();
|
||||||
|
const entries = Object.entries(data);
|
||||||
|
|
||||||
|
entries.forEach(async ([key, value]) => {
|
||||||
|
const isFileType = isFile(value) || (isArray(value) && value.length && isFile(value[0]));
|
||||||
|
|
||||||
|
if (isFileType) {
|
||||||
|
await transformFile(formData, key, value);
|
||||||
|
} else {
|
||||||
|
formData.append(key, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return formData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口为上传文件的类型时数据转换
|
* 接口为上传文件的类型时数据转换
|
||||||
* @param file - 单文件或多文件
|
|
||||||
* @param key - 文件的属性名
|
* @param key - 文件的属性名
|
||||||
|
* @param file - 单文件或多文件
|
||||||
*/
|
*/
|
||||||
async function transformFile(file: File[] | File, key: string) {
|
async function transformFile(formData: FormData, key: string, file: File[] | File) {
|
||||||
const formData = new FormData();
|
|
||||||
if (isArray(file)) {
|
if (isArray(file)) {
|
||||||
// 多文件
|
// 多文件
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@ -43,5 +58,4 @@ async function transformFile(file: File[] | File, key: string) {
|
|||||||
// 单文件
|
// 单文件
|
||||||
await formData.append(key, file);
|
await formData.append(key, file);
|
||||||
}
|
}
|
||||||
return formData;
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="403" />
|
<exception-base type="403" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../../system-view/components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="404" />
|
<exception-base type="404" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../../system-view/components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="500" />
|
<exception-base type="500" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../../system-view/components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import ExceptionBase from './ExceptionBase.vue';
|
|
||||||
|
|
||||||
export { ExceptionBase };
|
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="403" />
|
<exception-base type="403" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="404" />
|
<exception-base type="404" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="404" />
|
<exception-base type="404" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
<exception-base type="500" />
|
<exception-base type="500" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup></script>
|
||||||
import { ExceptionBase } from '../components';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
Loading…
Reference in New Issue
Block a user