defIndex.ts
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {store} from '/@/store';
import {defineStore} from 'pinia';
import {defHttp} from "@/utils/http/axios";
interface DefIndexState {
// 首页url
url: string,
// 首页组件
component: string
}
export const useDefIndexStore = defineStore({
id: 'defIndex',
state: (): DefIndexState => ({
url: '',
component: '',
}),
getters: {},
actions: {
/**
* 查询默认主页配置
*/
async query() {
const config = await defIndexApi.query();
this.url = config.url;
this.component = config.component;
},
/**
* 更新默认主页配置
* @param url 首页url
* @param component 首页组件
* @param isRoute 是否是路由
*/
async update(url: string, component: string, isRoute: boolean) {
await defIndexApi.update(url, component, isRoute);
await this.query()
},
check(url: string) {
return url === this.url;
}
}
});
// Need to be used outside the setup
export function useDefIndexStoreWithOut() {
return useDefIndexStore(store);
}
/**
* 默认首页配置API
*/
export const defIndexApi = {
/**
* 查询默认首页配置
*/
async query() {
const url = '/sys/sysRoleIndex/queryDefIndex'
return await defHttp.get({url});
},
/**
* 更新默认首页配置
* @param url 首页url
* @param component 首页组件
* @param isRoute 是否是路由
*/
async update(url: string, component: string, isRoute: boolean) {
let apiUrl = '/sys/sysRoleIndex/updateDefIndex'
apiUrl += '?url=' + url
apiUrl += '&component=' + component
apiUrl += '&isRoute=' + isRoute
return await defHttp.put({url: apiUrl});
},
}