main.ts
5.67 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import App from '@/App.vue';
import router from "@/router";
import Antd, {Form} from 'ant-design-vue';
import * as Vue from 'vue';
import axios, {AxiosInstance, AxiosStatic} from "axios";
import VueAxios from 'vue-axios';
import AutumnV from "./index";
// import "autumn-antv/dist/autumn-antv.css";
import store, {SecurityDirectiveA} from './store'
import './assets/style/main.less';
import 'echarts/lib/chart/bar';
import 'echarts/lib/chart/line';
import 'echarts/lib/chart/pie';
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/legend';
import 'echarts/lib/component/markPoint';
import 'echarts/lib/component/markLine';
import 'echarts/lib/component/graphic';
import 'echarts/lib/component/visualMap';
import {AuthService} from "@/common/AuthService";
import {CustomTokenInterceptor} from "@/common/CustomTokenInterceptor";
import filters from "@/filters/filters";
import {createI18n, useI18n} from "vue-i18n";
import messages from "./assets/i18n/index";
import ECharts from 'vue-echarts';
import {use} from 'echarts/core';
import {CanvasRenderer} from 'echarts/renderers';
import {BarChart, GaugeChart, GraphChart, LineChart, SankeyChart, MapChart, FunnelChart} from 'echarts/charts';
import {GridComponent, LegendComponent, TitleComponent, ToolboxComponent, TooltipComponent, VisualMapComponent} from 'echarts/components';
import Authenticity from "lib/src/core/security/Authenticity";
import Vue3ColorPicker from "vue3-colorpicker";
import "vue3-colorpicker/style.css";
import isoWeek from "dayjs/plugin/isoWeek";
import weekOfYear from "dayjs/plugin/weekOfYear";
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
import weekday from "dayjs/plugin/weekday";
import weekYear from "dayjs/plugin/weekYear";
import localeData from "dayjs/plugin/localeData";
import customParseFormat from "dayjs/plugin/customParseFormat";
import advancedFormat from "dayjs/plugin/advancedFormat";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import updateLocale from "dayjs/plugin/updateLocale";
import tinymce from 'tinymce/tinymce';
import {SecurityController} from "@/api/SecurityController";
import * as echarts from 'echarts/core';
import {WALDEN_THEME} from "@/assets/style/walden";
import SecurityDirective from "lib/src/core/security/SecurityDirective";
dayjs.locale("zh-cn");
dayjs.extend(customParseFormat);
dayjs.extend(advancedFormat);
dayjs.extend(localeData);
dayjs.extend(weekday);
dayjs.extend(weekYear);
dayjs.extend(weekOfYear);
dayjs.extend(isoWeek);
dayjs.extend(updateLocale);
dayjs.extend(quarterOfYear);
dayjs.updateLocale('zh-cn', {
weekStart: 1,
});
/**
* 自定义类型申明
*/
declare module '@vue/runtime-core' {
// export interface GlobalComponents {
// FontIcon:typeof fontIcon
// }
interface ComponentCustomProperties {
$auth: AuthService,
$filters: any,
$route: any,
$router: any,
$apiUrl: string,
$previewUrl: string,
$goBack: () => void
}
}
function goBack() {
router.go(-1);
}
use([
CanvasRenderer,
BarChart,
MapChart,
LineChart,
GaugeChart,
SankeyChart,
FunnelChart,
GraphChart,
GridComponent,
LegendComponent,
TooltipComponent,
TitleComponent,
VisualMapComponent,
ToolboxComponent
]);
const i18n = createI18n({
locale: 'zh_CN',
legacy: false,
globalInjection: true,
fallbackLocale: 'zh_CN',
messages: messages
});
const systemI18n = {
setup() {
const {locale, t} = useI18n();
return {locale, t};
}
};
// const obj = JSON.parse(data)
echarts.registerTheme('walden', WALDEN_THEME)
const apiUrl = import.meta.env.VITE_API_BASE_URL;
// 👇 最关键一步:挂到全局
(window as any).tinymce = tinymce
const axiosInstance: AxiosInstance = axios.create({timeout: 1000 * 60, baseURL: apiUrl, headers: {}});
export const authService: AuthService = new AuthService();
if (import.meta.env.MODE === 'development') {
authService.updateToken(import.meta.env.VITE_TOKEN);
} else if (import.meta.env.MODE === 'electron') {
authService.updateToken(import.meta.env.VITE_TOKEN);
} else {
const token: any = document.getElementById('token');
if (token) {
authService.updateToken(token.value);
} else {
window.location.href = 'login';
}
}
const app = Vue.createApp(App, systemI18n).use(store).use(router).use(Antd).use(Form).use(AutumnV).use(i18n).use(Vue3ColorPicker).use(VueAxios, axios);
// 全局注册组件(也可以使用局部注册)
app.component('v-chart', ECharts);
//注册自定义权限控制指令
app.directive('sec', SecurityDirectiveA);
app.config.globalProperties.axios = <AxiosStatic>axiosInstance;
//全局属性
const tokenInterceptor: CustomTokenInterceptor = new CustomTokenInterceptor(axiosInstance, authService);
app.config.globalProperties.$auth = authService;
app.config.globalProperties.axios = <AxiosStatic>axiosInstance;
app.config.globalProperties.$store = store;
app.config.globalProperties.$filters = filters;
app.config.globalProperties.$apiUrl = apiUrl;
app.config.globalProperties.$goBack = goBack;
app.provide('axios', app.config.globalProperties.axios);
//注册自定义权限控制指令
SecurityController.getUserAuthentication(axiosInstance as AxiosStatic, null).then((res) => {
const authenticity: Authenticity = res.data;
authenticity.token = authService.getToken();
authService.saveAuthentication(authenticity);
authService.setAuthentication(authenticity);
//将当前用户信息写入vuex的store中
store.commit('security/changeAuthenticity', authenticity);
//将用户的权限树写入到vuex的store中
store.commit('security/changePrivileges', authenticity.privileges ?? []);
app.mount('#app');
});
// app.mount('#app');