mirror of
https://github.com/vbenjs/gf-vben-admin.git
synced 2025-02-02 19:08:40 +08:00
合并
This commit is contained in:
parent
dba2ad329d
commit
0e26f8c813
@ -0,0 +1,14 @@
|
|||||||
|
import { defHttp } from '/@/utils/http/axios';
|
||||||
|
import { getMenuListResultModel } from './model/menuModel';
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
GetMenuList = '/router/list',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Get user menu based on id
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const getMenuList = () => {
|
||||||
|
return defHttp.get<getMenuListResultModel>({ url: Api.GetMenuList });
|
||||||
|
};
|
@ -26,19 +26,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
errorMessageMode: mode,
|
errorMessageMode: mode,
|
||||||
apiUrl: url,
|
apiUrl: 'http://localhost:10088',
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
export function registerApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
|
|
||||||
return defHttp.post(
|
|
||||||
{
|
|
||||||
url: Api.Register,
|
|
||||||
params,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
errorMessageMode: mode,
|
|
||||||
apiUrl: url,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,8 @@ const transform: AxiosTransform = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
throw new Error(message || t('sys.api.apiRequestFailed'));
|
||||||
|
},
|
||||||
|
|
||||||
// 请求之前处理config
|
// 请求之前处理config
|
||||||
beforeRequestHook: (config, options) => {
|
beforeRequestHook: (config, options) => {
|
||||||
|
@ -10,66 +10,61 @@
|
|||||||
<BasicForm @register="registerForm" />
|
<BasicForm @register="registerForm" />
|
||||||
</BasicDrawer>
|
</BasicDrawer>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts">
|
||||||
import { ref, computed, unref } from 'vue';
|
import { defineComponent, ref, computed, unref } from 'vue';
|
||||||
import { BasicForm, useForm } from '/@/components/Form/index';
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
||||||
import { formSchema } from './menu.data';
|
import { formSchema } from './menu.data';
|
||||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
||||||
import { Curd } from '/@/api/Curd';
|
|
||||||
|
|
||||||
const emit = defineEmits(['success', 'register']);
|
import { getMenuList } from '/@/api/demo/system';
|
||||||
const isUpdate = ref(true);
|
|
||||||
const id = ref(0);
|
|
||||||
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
|
|
||||||
labelWidth: 100,
|
|
||||||
schemas: formSchema,
|
|
||||||
showActionButtonGroup: false,
|
|
||||||
baseColProps: { lg: 12, md: 24 },
|
|
||||||
});
|
|
||||||
|
|
||||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
export default defineComponent({
|
||||||
resetFields();
|
name: 'MenuDrawer',
|
||||||
setDrawerProps({ confirmLoading: false });
|
components: { BasicDrawer, BasicForm },
|
||||||
isUpdate.value = !!data?.isUpdate;
|
emits: ['success', 'register'],
|
||||||
const { record } = data;
|
setup(_, { emit }) {
|
||||||
|
const isUpdate = ref(true);
|
||||||
|
|
||||||
console.log(record);
|
const [registerForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
|
||||||
if (unref(isUpdate)) {
|
labelWidth: 100,
|
||||||
id.value = record.id;
|
schemas: formSchema,
|
||||||
setFieldsValue({
|
showActionButtonGroup: false,
|
||||||
...record,
|
baseColProps: { lg: 12, md: 24 },
|
||||||
title: record.meta.title,
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
let treeData = [{ name: '无父级', value: 0, id: 0 }];
|
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
||||||
const res = await Curd({ i: 'router', a: 'list' });
|
resetFields();
|
||||||
treeData = treeData.concat(res.items);
|
setDrawerProps({ confirmLoading: false });
|
||||||
// console.log(treeData);
|
isUpdate.value = !!data?.isUpdate;
|
||||||
updateSchema({
|
|
||||||
field: 'parent',
|
|
||||||
componentProps: { treeData },
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增菜单' : '编辑菜单'));
|
if (unref(isUpdate)) {
|
||||||
|
setFieldsValue({
|
||||||
|
...data.record,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const treeData = await getMenuList();
|
||||||
|
updateSchema({
|
||||||
|
field: 'parentMenu',
|
||||||
|
componentProps: { treeData },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
async function handleSubmit() {
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增菜单' : '编辑菜单'));
|
||||||
try {
|
|
||||||
const values = await validate();
|
async function handleSubmit() {
|
||||||
setDrawerProps({ confirmLoading: true });
|
try {
|
||||||
// TODO custom api
|
const values = await validate();
|
||||||
console.log(values);
|
setDrawerProps({ confirmLoading: true });
|
||||||
if (unref(isUpdate)) {
|
// TODO custom api
|
||||||
await Curd({ i: 'router', a: 'edit', id: id.value, ...values });
|
console.log(values);
|
||||||
} else {
|
closeDrawer();
|
||||||
await Curd({ i: 'router', a: 'add', ...values });
|
emit('success');
|
||||||
|
} finally {
|
||||||
|
setDrawerProps({ confirmLoading: false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDrawer();
|
return { registerDrawer, registerForm, getTitle, handleSubmit };
|
||||||
emit('success');
|
},
|
||||||
} finally {
|
});
|
||||||
setDrawerProps({ confirmLoading: false });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -106,10 +106,10 @@ const formRef = ref();
|
|||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const rememberMe = ref(false);
|
const rememberMe = ref(false);
|
||||||
|
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
account: '',
|
account: 'admin',
|
||||||
password: '',
|
password: '123456',
|
||||||
});
|
});
|
||||||
|
|
||||||
const { validForm } = useFormValid(formRef);
|
const { validForm } = useFormValid(formRef);
|
||||||
|
|
||||||
@ -117,33 +117,33 @@ const { validForm } = useFormValid(formRef);
|
|||||||
|
|
||||||
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
|
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN);
|
||||||
|
|
||||||
async function handleLogin() {
|
async function handleLogin() {
|
||||||
const data = await validForm();
|
const data = await validForm();
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
try {
|
try {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const userInfo = await userStore.login(
|
const userInfo = await userStore.login(
|
||||||
toRaw({
|
toRaw({
|
||||||
password: data.password,
|
password: data.password,
|
||||||
username: data.account,
|
username: data.account,
|
||||||
mode: 'none', //不要默认的错误提示
|
mode: 'none', //不要默认的错误提示
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
notification.success({
|
notification.success({
|
||||||
message: t('sys.login.loginSuccessTitle'),
|
message: t('sys.login.loginSuccessTitle'),
|
||||||
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.username}`,
|
description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.username}`,
|
||||||
duration: 3,
|
duration: 3,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
createErrorModal({
|
||||||
|
title: t('sys.api.errorTip'),
|
||||||
|
content: error.message || t('sys.api.networkExceptionMsg'),
|
||||||
|
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body,
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
createErrorModal({
|
|
||||||
title: t('sys.api.errorTip'),
|
|
||||||
content: error.message || t('sys.api.networkExceptionMsg'),
|
|
||||||
getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user