feat(个人中心): 个人中心 -apikey&本地执行&构建报错 fix

This commit is contained in:
baiqi 2023-12-05 14:04:19 +08:00 committed by 刘瑞斌
parent 2ee166f00e
commit 9acba4f68e
12 changed files with 455 additions and 180 deletions

View File

@ -1,7 +1,34 @@
import MSR from '@/api/http/index'; import MSR from '@/api/http/index';
import { GetMenuListUrl, getPublicKeyUrl, isLoginUrl, LoginUrl, LogoutUrl } from '@/api/requrls/user'; import {
AddAPIKEYUrl,
AddLocalConfigUrl,
DeleteAPIKEYUrl,
DisableAPIKEYUrl,
DisableLocalConfigUrl,
EnableAPIKEYUrl,
EnableLocalConfigUrl,
GetAPIKEYListUrl,
GetLocalConfigUrl,
GetMenuListUrl,
GetPublicKeyUrl,
isLoginUrl,
LoginUrl,
LogoutUrl,
UpdateAPIKEYUrl,
UpdateLocalConfigUrl,
ValidAPIKEYUrl,
ValidLocalConfigUrl,
} from '@/api/requrls/user';
import type { LoginData, LoginRes } from '@/models/user'; import type {
AddLocalConfigParams,
APIKEY,
LocalConfig,
LoginData,
LoginRes,
UpdateAPIKEYParams,
UpdateLocalConfigParams,
} from '@/models/user';
import type { RouteRecordNormalized } from 'vue-router'; import type { RouteRecordNormalized } from 'vue-router';
@ -22,5 +49,70 @@ export function getMenuList() {
} }
export function getPublicKeyRequest() { export function getPublicKeyRequest() {
return MSR.get<string>({ url: getPublicKeyUrl }, { ignoreCancelToken: true }); return MSR.get<string>({ url: GetPublicKeyUrl }, { ignoreCancelToken: true });
}
// 个人设置-更新本地执行
export function updateLocalConfig(data: UpdateLocalConfigParams) {
return MSR.post({ url: UpdateLocalConfigUrl, data });
}
// 个人设置-添加本地执行
export function addLocalConfig(data: AddLocalConfigParams) {
return MSR.post({ url: AddLocalConfigUrl, data });
}
// 个人设置-验证本地执行配置
export function validLocalConfig(id: string) {
return MSR.get<boolean>({ url: ValidLocalConfigUrl, params: id });
}
// 个人设置-获取本地执行配置
export function getLocalConfig() {
return MSR.get<LocalConfig[]>({ url: GetLocalConfigUrl });
}
// 个人设置-启用本地执行配置
export function enableLocalConfig(id: string) {
return MSR.get({ url: EnableLocalConfigUrl, params: id });
}
// 个人设置-禁用本地执行配置
export function disableLocalConfig(id: string) {
return MSR.get({ url: DisableLocalConfigUrl, params: id });
}
// 个人设置-修改 APIKEY
export function updateAPIKEY(data: UpdateAPIKEYParams) {
return MSR.post({ url: UpdateAPIKEYUrl, data });
}
// 个人设置-验证 APIKEY
export function validAPIKEY() {
return MSR.get({ url: ValidAPIKEYUrl });
}
// 个人设置-获取 APIKEY 列表
export function getAPIKEYList() {
return MSR.get<APIKEY[]>({ url: GetAPIKEYListUrl });
}
// 个人设置-开启 APIKEY
export function enableAPIKEY(id: string) {
return MSR.get({ url: EnableAPIKEYUrl, params: id });
}
// 个人设置-关闭 APIKEY
export function disableAPIKEY(id: string) {
return MSR.get({ url: DisableAPIKEYUrl, params: id });
}
// 个人设置-删除 APIKEY
export function deleteAPIKEY(id: string) {
return MSR.get({ url: DeleteAPIKEYUrl, params: id });
}
// 个人设置-生成 APIKEY
export function addAPIKEY() {
return MSR.get({ url: AddAPIKEYUrl });
} }

View File

@ -2,4 +2,17 @@ export const LoginUrl = '/login';
export const isLoginUrl = '/is-login'; export const isLoginUrl = '/is-login';
export const LogoutUrl = '/signout'; export const LogoutUrl = '/signout';
export const GetMenuListUrl = '/api/user/menu'; export const GetMenuListUrl = '/api/user/menu';
export const getPublicKeyUrl = '/get-key'; export const GetPublicKeyUrl = '/get-key';
export const UpdateLocalConfigUrl = '/user/local/config/update'; // 个人设置-更新本地执行配置
export const AddLocalConfigUrl = '/user/local/config/add'; // 个人设置-添加本地执行
export const ValidLocalConfigUrl = '/user/local/config/validate'; // 个人设置-验证本地执行
export const GetLocalConfigUrl = '/user/local/config/get'; // 个人设置-获取本地执行配置
export const EnableLocalConfigUrl = '/user/local/config/enable'; // 个人设置-启用本地执行配置
export const DisableLocalConfigUrl = '/user/local/config/disable'; // 个人设置-禁用本地执行配置
export const UpdateAPIKEYUrl = '/user/api/key/update'; // 个人设置-更新 APIKEY
export const ValidAPIKEYUrl = '/user/api/key/validate'; // 个人设置-验证 APIKEY
export const GetAPIKEYListUrl = '/user/api/key/list'; // 个人设置-获取 APIKEY 列表
export const EnableAPIKEYUrl = '/user/api/key/enable'; // 个人设置-开启 APIKEY
export const DisableAPIKEYUrl = '/user/api/key/disable'; // 个人设置-关闭 APIKEY
export const DeleteAPIKEYUrl = '/user/api/key/delete'; // 个人设置-删除 APIKEY
export const AddAPIKEYUrl = '/user/api/key/add'; // 个人设置-生成 APIKEY

View File

@ -62,4 +62,5 @@ declare global {
declare global { declare global {
// @ts-ignore // @ts-ignore
export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
import('vue')
} }

View File

@ -10,7 +10,15 @@
</a-tooltip> </a-tooltip>
</div> </div>
<a-tooltip :content="t('ms.personal.maxTip')" position="right" :disabled="apiKeyList.length < 5"> <a-tooltip :content="t('ms.personal.maxTip')" position="right" :disabled="apiKeyList.length < 5">
<a-button type="outline" class="w-[60px]" :disabled="apiKeyList.length >= 5">{{ t('common.new') }}</a-button> <a-button
type="outline"
class="w-[60px]"
:disabled="apiKeyList.length >= 5"
:loading="newLoading"
@click="newApiKey"
>
{{ t('common.new') }}
</a-button>
</a-tooltip> </a-tooltip>
<a-spin class="api-list-content" :loading="loading"> <a-spin class="api-list-content" :loading="loading">
<div v-for="item of apiKeyList" :key="item.id" class="api-item"> <div v-for="item of apiKeyList" :key="item.id" class="api-item">
@ -38,14 +46,16 @@
</div> </div>
<div class="px-[16px]"> <div class="px-[16px]">
<div class="api-item-label">{{ t('ms.personal.desc') }}</div> <div class="api-item-label">{{ t('ms.personal.desc') }}</div>
<a-tooltip :content="item.desc"> <a-tooltip :content="item.description" :disabled="!item.description">
<div class="api-item-value one-line-text">{{ item.desc }}</div> <div class="api-item-value one-line-text">{{ item.description || '-' }}</div>
</a-tooltip> </a-tooltip>
<div class="api-item-label">{{ t('ms.personal.createTime') }}</div> <div class="api-item-label">{{ t('ms.personal.createTime') }}</div>
<div class="api-item-value">{{ dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}</div> <div class="api-item-value">
{{ dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}
</div>
<div class="api-item-label">{{ t('ms.personal.expireTime') }}</div> <div class="api-item-label">{{ t('ms.personal.expireTime') }}</div>
<div class="api-item-value"> <div class="api-item-value">
{{ dayjs(item.expireTime).format('YYYY-MM-DD HH:mm:ss') }} {{ item.forever ? t('ms.personal.forever') : dayjs(item.expireTime).format('YYYY-MM-DD HH:mm:ss') }}
<a-tooltip v-if="item.isExpire" :content="t('ms.personal.expiredTip')"> <a-tooltip v-if="item.isExpire" :content="t('ms.personal.expiredTip')">
<MsIcon type="icon-icon_warning_filled" class="ml-[4px] text-[rgb(var(--warning-6))]" /> <MsIcon type="icon-icon_warning_filled" class="ml-[4px] text-[rgb(var(--warning-6))]" />
</a-tooltip> </a-tooltip>
@ -61,7 +71,7 @@
v-model:model-value="item.enable" v-model:model-value="item.enable"
size="small" size="small"
:before-change="() => handleBeforeEnableChange(item)" :before-change="() => handleBeforeEnableChange(item)"
></a-switch> />
</div> </div>
</div> </div>
</a-spin> </a-spin>
@ -112,6 +122,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onBeforeMount } from 'vue';
import { useClipboard } from '@vueuse/core'; import { useClipboard } from '@vueuse/core';
import { FormInstance, Message } from '@arco-design/web-vue'; import { FormInstance, Message } from '@arco-design/web-vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@ -121,83 +132,66 @@
import { ActionsItem } from '@/components/pure/ms-table-more-action/types'; import { ActionsItem } from '@/components/pure/ms-table-more-action/types';
import MsTag from '@/components/pure/ms-tag/ms-tag.vue'; import MsTag from '@/components/pure/ms-tag/ms-tag.vue';
import {
addAPIKEY,
deleteAPIKEY,
disableAPIKEY,
enableAPIKEY,
getAPIKEYList,
updateAPIKEY,
} from '@/api/modules/user/index';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal'; import useModal from '@/hooks/useModal';
import { APIKEY } from '@/models/user';
const { copy } = useClipboard(); const { copy } = useClipboard();
const { t } = useI18n(); const { t } = useI18n();
const { openModal } = useModal(); const { openModal } = useModal();
interface ApiKeyItem { const loading = ref(false);
id: string; interface APIKEYItem extends APIKEY {
accessKey: string;
secretKey: string;
desc: string;
createTime: number;
expireTime: number;
enable: boolean;
desensitization: boolean;
isExpire: boolean; isExpire: boolean;
desensitization: boolean;
}
const apiKeyList = ref<APIKEYItem[]>([]);
async function initApiKeys() {
try {
loading.value = true;
const res = await getAPIKEYList();
apiKeyList.value = res.map((item) => ({
...item,
isExpire: item.forever ? false : item.expireTime < Date.now(),
desensitization: true,
}));
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
loading.value = false;
}
}
onBeforeMount(() => {
initApiKeys();
});
const newLoading = ref(false);
async function newApiKey() {
try {
newLoading.value = true;
await addAPIKEY();
Message.success(t('common.newSuccess'));
initApiKeys();
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
newLoading.value = false;
}
} }
const loading = ref(false);
const apiKeyList = ref<ApiKeyItem[]>([
{
id: '238dy23d2',
accessKey: 'dueiouhwded',
secretKey: 'asdasdas',
desc: '92387yd9283d2',
createTime: 1629782400000,
expireTime: 1629982400000,
enable: true,
desensitization: true,
isExpire: false,
},
{
id: 'ih02i3d23',
accessKey: 'sdshsd',
secretKey: 'poj4f',
desc: '92387yd9283d2',
createTime: 1629782400000,
expireTime: 1629982400000,
enable: false,
desensitization: true,
isExpire: true,
},
{
id: '34hy34h3',
accessKey: 'sdshsd',
secretKey: 'poj4f',
desc: '92387yd9283d2',
createTime: 1629782400000,
expireTime: 1629982400000,
enable: false,
desensitization: true,
isExpire: true,
},
{
id: 'f23',
accessKey: 'sdshsd',
secretKey: 'poj4f',
desc: '92387yd9283d2',
createTime: 1629782400000,
expireTime: 1629982400000,
enable: false,
desensitization: true,
isExpire: true,
},
{
id: 'ih02i3ed23',
accessKey: 'sdshsd',
secretKey: 'poj4f',
desc: '92387yd9283d2',
createTime: 1629782400000,
expireTime: 1629982400000,
enable: false,
desensitization: true,
isExpire: true,
},
]);
const actions: ActionsItem[] = [ const actions: ActionsItem[] = [
{ {
label: t('ms.personal.validTime'), label: t('ms.personal.validTime'),
@ -218,11 +212,11 @@
Message.success(t('ms.personal.copySuccess')); Message.success(t('ms.personal.copySuccess'));
} }
function desensitization(item: ApiKeyItem) { function desensitization(item: APIKEYItem) {
item.desensitization = !item.desensitization; item.desensitization = !item.desensitization;
} }
async function handleBeforeEnableChange(item: ApiKeyItem) { async function handleBeforeEnableChange(item: APIKEYItem) {
if (item.enable) { if (item.enable) {
openModal({ openModal({
type: 'error', type: 'error',
@ -235,7 +229,9 @@
}, },
onBeforeOk: async () => { onBeforeOk: async () => {
try { try {
await disableAPIKEY(item.id);
Message.success(t('ms.personal.closeSuccess')); Message.success(t('ms.personal.closeSuccess'));
item.enable = false;
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
@ -246,15 +242,17 @@
return false; return false;
} }
try { try {
await enableAPIKEY(item.id);
Message.success(t('ms.personal.openSuccess')); Message.success(t('ms.personal.openSuccess'));
return true; return true;
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console
console.log(error); console.log(error);
return false; return false;
} }
} }
function deleteApiKey(item: ApiKeyItem) { function deleteApiKey(item: APIKEYItem) {
openModal({ openModal({
type: 'error', type: 'error',
title: t('ms.personal.confirmDelete'), title: t('ms.personal.confirmDelete'),
@ -266,7 +264,9 @@
}, },
onBeforeOk: async () => { onBeforeOk: async () => {
try { try {
await deleteAPIKEY(item.id);
Message.success(t('common.deleteSuccess')); Message.success(t('common.deleteSuccess'));
initApiKeys();
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
@ -290,8 +290,15 @@
timeFormRef.value?.validate(async (errors) => { timeFormRef.value?.validate(async (errors) => {
if (!errors) { if (!errors) {
try { try {
await updateAPIKEY({
id: apiKeyList.value[0].id,
description: timeForm.value.desc,
expireTime: timeForm.value.activeTimeType === 'forever' ? 0 : dayjs(timeForm.value.time).valueOf(),
forever: timeForm.value.activeTimeType === 'forever',
});
Message.success(t('common.updateSuccess')); Message.success(t('common.updateSuccess'));
done(true); done(true);
initApiKeys();
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
@ -308,12 +315,12 @@
timeForm.value = { ...defaultTimeForm }; timeForm.value = { ...defaultTimeForm };
} }
function handleMoreActionSelect(item: ActionsItem, apiKey: ApiKeyItem) { function handleMoreActionSelect(item: ActionsItem, apiKey: APIKEYItem) {
if (item.eventTag === 'time') { if (item.eventTag === 'time') {
timeForm.value = { timeForm.value = {
activeTimeType: 'forever', activeTimeType: apiKey.forever ? 'forever' : 'custom',
time: apiKey.expireTime ? dayjs(apiKey.expireTime).format('YYYY-MM-DD HH:mm:ss') : '', time: apiKey.expireTime ? dayjs(apiKey.expireTime).format('YYYY-MM-DD HH:mm:ss') : '',
desc: apiKey.desc, desc: apiKey.description,
}; };
timeModalVisible.value = true; timeModalVisible.value = true;
} else if (item.eventTag === 'delete') { } else if (item.eventTag === 'delete') {

View File

@ -2,25 +2,33 @@
<div class="mb-[16px] flex items-center justify-between"> <div class="mb-[16px] flex items-center justify-between">
<div class="font-medium text-[var(--color-text-1)]">{{ t('ms.personal.localExecution') }}</div> <div class="font-medium text-[var(--color-text-1)]">{{ t('ms.personal.localExecution') }}</div>
</div> </div>
<a-spin class="w-full" :loading="loading">
<div class="grid grid-cols-2 gap-[16px]"> <div class="grid grid-cols-2 gap-[16px]">
<div class="config-card"> <div class="config-card">
<div class="config-card-title"> <div class="config-card-title">
<div class="config-card-title-text">{{ t('ms.personal.apiLocalExecution') }}</div> <div class="config-card-title-text">{{ t('ms.personal.apiLocalExecution') }}</div>
<MsTag theme="outline" :type="tagMap[apiConfig.status].type" size="small" class="px-[4px]"> <MsTag
v-if="apiConfig.status !== 'none'"
theme="outline"
:type="tagMap[apiConfig.status].type"
size="small"
class="px-[4px]"
>
{{ tagMap[apiConfig.status].text }} {{ tagMap[apiConfig.status].text }}
</MsTag> </MsTag>
</div> </div>
<a-input <a-input
v-model:model-value="apiConfig.url" v-model:model-value="apiConfig.userUrl"
:placeholder="t('ms.personal.apiLocalExecutionPlaceholder')" :placeholder="t('ms.personal.apiLocalExecutionPlaceholder')"
class="mb-[16px]" class="mb-[16px]"
@press-enter="testApi"
></a-input> ></a-input>
<div class="config-card-footer"> <div class="config-card-footer">
<a-button <a-button
type="outline" type="outline"
class="px-[8px]" class="px-[8px]"
size="mini" size="mini"
:disabled="apiConfig.url.trim() === ''" :disabled="apiConfig.userUrl.trim() === ''"
:loading="testApiLoading" :loading="testApiLoading"
@click="testApi" @click="testApi"
> >
@ -31,9 +39,9 @@
{{ t('ms.personal.priorityLocalExec') }} {{ t('ms.personal.priorityLocalExec') }}
</div> </div>
<a-switch <a-switch
v-model:model-value="apiConfig.isPriorityLocalExec" v-model:model-value="apiConfig.enable"
size="small" size="small"
:disabled="apiConfig.status !== 1 || testApiLoading" :disabled="apiConfig.id === '' || testApiLoading"
:before-change="(val) => handleApiPriorityBeforeChange(val)" :before-change="(val) => handleApiPriorityBeforeChange(val)"
/> />
</div> </div>
@ -42,21 +50,28 @@
<div class="config-card"> <div class="config-card">
<div class="config-card-title"> <div class="config-card-title">
<div class="config-card-title-text">{{ t('ms.personal.uiLocalExecution') }}</div> <div class="config-card-title-text">{{ t('ms.personal.uiLocalExecution') }}</div>
<MsTag theme="outline" :type="tagMap[uiConfig.status].type" size="small" class="px-[4px]"> <MsTag
v-if="uiConfig.status !== 'none'"
theme="outline"
:type="tagMap[uiConfig.status].type"
size="small"
class="px-[4px]"
>
{{ tagMap[uiConfig.status].text }} {{ tagMap[uiConfig.status].text }}
</MsTag> </MsTag>
</div> </div>
<a-input <a-input
v-model:model-value="uiConfig.url" v-model:model-value="uiConfig.userUrl"
:placeholder="t('ms.personal.uiLocalExecutionPlaceholder')" :placeholder="t('ms.personal.uiLocalExecutionPlaceholder')"
class="mb-[16px]" class="mb-[16px]"
@press-enter="testUi"
></a-input> ></a-input>
<div class="config-card-footer"> <div class="config-card-footer">
<a-button <a-button
type="outline" type="outline"
class="px-[8px]" class="px-[8px]"
size="mini" size="mini"
:disabled="uiConfig.url.trim() === ''" :disabled="uiConfig.userUrl.trim() === ''"
:loading="testUiLoading" :loading="testUiLoading"
@click="testUi" @click="testUi"
> >
@ -67,31 +82,46 @@
{{ t('ms.personal.priorityLocalExec') }} {{ t('ms.personal.priorityLocalExec') }}
</div> </div>
<a-switch <a-switch
v-model:model-value="uiConfig.isPriorityLocalExec" v-model:model-value="uiConfig.enable"
size="small" size="small"
:disabled="uiConfig.status !== 1 || testUiLoading" :disabled="uiConfig.id === '' || testUiLoading"
:before-change="(val) => handleUiPriorityBeforeChange(val)" :before-change="(val) => handleUiPriorityBeforeChange(val)"
/> />
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</a-spin>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { onBeforeMount } from 'vue';
import { Message } from '@arco-design/web-vue'; import { Message } from '@arco-design/web-vue';
import MsTag, { TagType } from '@/components/pure/ms-tag/ms-tag.vue'; import MsTag, { TagType } from '@/components/pure/ms-tag/ms-tag.vue';
import {
addLocalConfig,
disableLocalConfig,
enableLocalConfig,
getLocalConfig,
updateLocalConfig,
validLocalConfig,
} from '@/api/modules/user/index';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import { LocalConfig } from '@/models/user';
const { t } = useI18n(); const { t } = useI18n();
type Status = 0 | 1 | 2; type Status = 0 | 1 | 2 | 'none'; // 0 1 2
interface TagMapItem { interface TagMapItem {
type: TagType; type: TagType;
text: string; text: string;
} }
interface Config {
status: Status;
}
const tagMap: Record<Status, TagMapItem> = { const tagMap: Record<Status, TagMapItem> = {
0: { 0: {
type: 'default', type: 'default',
@ -105,18 +135,44 @@
type: 'danger', type: 'danger',
text: t('ms.personal.testFail'), text: t('ms.personal.testFail'),
}, },
none: {
type: 'default',
text: '',
},
}; };
const loading = ref(false);
const testApiLoading = ref(false); const testApiLoading = ref(false);
const apiConfig = ref({ const apiConfig = ref<LocalConfig & Config>({
url: '', id: '',
status: 1 as Status, userUrl: '',
isPriorityLocalExec: false, enable: false,
type: 'API',
status: 0,
}); });
async function testApi() { async function testApi() {
try { try {
testApiLoading.value = true; testApiLoading.value = true;
if (apiConfig.value.id) {
//
await updateLocalConfig({
id: apiConfig.value.id,
userUrl: apiConfig.value.userUrl.trim(),
});
} else {
const result = await addLocalConfig({
type: 'API',
userUrl: apiConfig.value.userUrl.trim(),
});
apiConfig.value.id = result.id;
}
const res = await validLocalConfig(apiConfig.value.id);
apiConfig.value.status = res ? 1 : 2;
if (res) {
Message.success(t('ms.personal.testPass')); Message.success(t('ms.personal.testPass'));
} else {
Message.error(t('ms.personal.testFail'));
}
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
@ -127,6 +183,11 @@
async function handleApiPriorityBeforeChange(val: string | number | boolean) { async function handleApiPriorityBeforeChange(val: string | number | boolean) {
try { try {
if (val) {
await enableLocalConfig(apiConfig.value.id);
} else {
await disableLocalConfig(apiConfig.value.id);
}
Message.success(val ? t('ms.personal.apiLocalExecutionOpen') : t('ms.personal.apiLocalExecutionClose')); Message.success(val ? t('ms.personal.apiLocalExecutionOpen') : t('ms.personal.apiLocalExecutionClose'));
return true; return true;
} catch (error) { } catch (error) {
@ -137,26 +198,52 @@
} }
const testUiLoading = ref(false); const testUiLoading = ref(false);
const uiConfig = ref({ const uiConfig = ref<LocalConfig & Config>({
url: '', id: '',
status: 1 as Status, userUrl: '',
isPriorityLocalExec: false, enable: false,
type: 'UI',
status: 0,
}); });
async function testUi() { async function testUi() {
try { try {
testApiLoading.value = true; testUiLoading.value = true;
if (uiConfig.value.id) {
//
await updateLocalConfig({
id: uiConfig.value.id,
userUrl: uiConfig.value.userUrl.trim(),
});
} else {
const result = await addLocalConfig({
type: 'UI',
userUrl: uiConfig.value.userUrl.trim(),
});
uiConfig.value.id = result.id;
}
const res = await validLocalConfig(uiConfig.value.id);
uiConfig.value.status = res ? 1 : 2;
if (res) {
Message.success(t('ms.personal.testPass')); Message.success(t('ms.personal.testPass'));
} else {
Message.error(t('ms.personal.testFail'));
}
} catch (error) { } catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log(error); console.log(error);
} finally { } finally {
testApiLoading.value = false; testUiLoading.value = false;
} }
} }
async function handleUiPriorityBeforeChange(val: string | number | boolean) { async function handleUiPriorityBeforeChange(val: string | number | boolean) {
try { try {
if (val) {
await enableLocalConfig(uiConfig.value.id);
} else {
await disableLocalConfig(uiConfig.value.id);
}
Message.success(val ? t('ms.personal.uiLocalExecutionOpen') : t('ms.personal.uiLocalExecutionClose')); Message.success(val ? t('ms.personal.uiLocalExecutionOpen') : t('ms.personal.uiLocalExecutionClose'));
return true; return true;
} catch (error) { } catch (error) {
@ -165,6 +252,33 @@
return false; return false;
} }
} }
onBeforeMount(async () => {
try {
loading.value = true;
const res = await getLocalConfig();
if (Array.isArray(res)) {
res.forEach((config) => {
if (config.type === 'API') {
apiConfig.value = {
...config,
status: 'none',
};
} else if (config.type === 'UI') {
uiConfig.value = {
...config,
status: 'none',
};
}
});
}
} catch (error) {
// eslint-disable-next-line no-console
console.log(error);
} finally {
loading.value = false;
}
});
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>

View File

@ -50,14 +50,18 @@
} }
); );
const activeMenu = ref('baseInfo');
watch( watch(
() => innerVisible.value, () => innerVisible.value,
(val) => { (val) => {
emit('update:visible', val); emit('update:visible', val);
if (!val) {
activeMenu.value = 'baseInfo';
}
} }
); );
const activeMenu = ref('baseInfo');
const menuList = ref([ const menuList = ref([
{ {
name: 'personal', name: 'personal',

View File

@ -59,11 +59,11 @@
// cascadeitem // cascadeitem
if (currentFormCreateRules) { if (currentFormCreateRules) {
const cascade = currentFormCreateRules const cascade = currentFormCreateRules
.map((item: Record<string, any>) => item.link) .map((item) => item.link)
.filter((item: Record<string, any>) => item) .filter((item) => item)
.flatMap((flatItem: any) => flatItem); .flatMap((flatItem: any) => flatItem);
// linkitem // linkitem
return currentFormCreateRules.filter((item: Record<string, any>) => { return currentFormCreateRules.filter((item) => {
return cascade.indexOf(item.field) > -1; return cascade.indexOf(item.field) > -1;
}); });
} }
@ -88,9 +88,9 @@
(val) => { (val) => {
// options // options
if (val) { if (val) {
val.forEach(async (item: any) => { val.forEach((item) => {
if (item.value) { if (item.value) {
await getOptionsRequest(item); getOptionsRequest(item as FormRuleItem);
} }
}); });
} }

View File

@ -42,6 +42,13 @@
const currentKey = ref(props.defaultKey); const currentKey = ref(props.defaultKey);
watch(
() => props.defaultKey,
(val) => {
currentKey.value = val;
}
);
const toggleMenu = (itemName: string) => { const toggleMenu = (itemName: string) => {
if (itemName) { if (itemName) {
currentKey.value = itemName; currentKey.value = itemName;

View File

@ -75,4 +75,5 @@ export default {
'common.more': 'More', 'common.more': 'More',
'common.recycle': 'Recycle Bin', 'common.recycle': 'Recycle Bin',
'common.new': 'New', 'common.new': 'New',
'common.newSuccess': 'Added successfully',
}; };

View File

@ -75,4 +75,5 @@ export default {
'common.more': '更多', 'common.more': '更多',
'common.recycle': '回收站', 'common.recycle': '回收站',
'common.new': '新增', 'common.new': '新增',
'common.newSuccess': '新增成功',
}; };

View File

@ -37,3 +37,42 @@ export interface LoginRes {
userRoleRelations: UserRole[]; userRoleRelations: UserRole[];
userRoles: UserRole[]; userRoles: UserRole[];
} }
// 更新本地执行配置
export interface UpdateLocalConfigParams {
id: string;
userUrl: string;
}
// 本地执行配置类型
export type LocalConfigType = 'API' | 'UI';
// 添加本地执行
export interface AddLocalConfigParams {
userUrl: string;
type: LocalConfigType;
}
// 本地执行配置
export interface LocalConfig {
id: string;
userUrl: string;
enable: boolean;
type: LocalConfigType;
createUser?: string;
}
// 更新 APIKEY
export interface UpdateAPIKEYParams {
id: string;
forever: boolean;
expireTime: number;
description: string;
}
// APIKEY
export interface APIKEY {
id: string;
createUser: string;
accessKey: string;
secretKey: string;
createTime: number;
enable: boolean;
forever: boolean;
expireTime: number;
description: string;
}

View File

@ -7,8 +7,6 @@ import { useI18n } from '@/hooks/useI18n';
import { FormCreateKeyEnum } from '@/enums/formCreateEnum'; import { FormCreateKeyEnum } from '@/enums/formCreateEnum';
import type { Rule } from '@form-create/arco-design';
const { t } = useI18n(); const { t } = useI18n();
const useFormCreateStore = defineStore('form-create', { const useFormCreateStore = defineStore('form-create', {
persist: false, persist: false,
@ -111,13 +109,11 @@ const useFormCreateStore = defineStore('form-create', {
const formValue = formValueApi.formData(); const formValue = formValueApi.formData();
// 设置自定义属性给到searchSelect // 设置自定义属性给到searchSelect
const formCreateRuleArr = this.formCreateRuleMap.get(key); const formCreateRuleArr = this.formCreateRuleMap.get(key);
if (formCreateRuleArr) { const formCreateItem = formCreateRuleArr?.find((items) => cascadeItem.field === items.field);
const formCreateItem = formCreateRuleArr.find((item: FormRuleItem) => cascadeItem.field === item.field); if (formCreateItem) {
if (formCreateItem && formCreateItem.props) {
formCreateItem.props.keyword = val.value; formCreateItem.props.keyword = val.value;
formCreateItem.props.formValue = formValue; formCreateItem.props.formValue = formValue;
} }
}
}, },
}, },
getters: {}, getters: {},