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
| <template>
| <div ref="amisPageRef" class="amis-page"></div>
| </template>
|
| <script setup lang="ts">
| import { Local } from '@icon-park/vue-next';
|
| import 'amis/sdk/sdk.js';
| import { onMounted, onUnmounted, ref } from 'vue';
| import { NO_AUTH_API_LIST } from '/@/api/ai/chat';
| import { LOGIN_URL, TEL_LOGIN_URL } from '/@/api/ai/user';
| import { MAIN_URL } from '/@/constants';
| import router from '/@/router';
| import { accessSessionKey, handleNoAuth } from '/@/utils/request';
|
| const amisPageRef = ref<HTMLDivElement>(null);
|
| const schema = {
| type: 'page',
| title: '表单页面',
| body: [
| {
| type: 'form',
| mode: 'horizontal',
| api: {
| url: '/system/get_sys_notify_list',
| dataType: 'form',
| },
|
| body: [
| {
| label: 'Name',
| type: 'input-text',
| name: 'name',
| },
| {
| label: 'Email',
| type: 'input-email',
| placeholder: '请输入邮箱地址',
| name: 'email',
| },
| // {
| // type: 'editor',
| // name: 'js',
| // label: 'JS',
| // language: 'javascript',
| // },
| ],
| },
| ],
| };
| let amisInstance = null;
| onMounted(() => {
| let amis = amisRequire('amis/embed');
| amisInstance = amis.embed(
| '.amis-page',
| schema,
| {
|
| },
| {
| requestAdaptor(api) {
| // 支持异步,可以通过 api.mockResponse 来设置返回结果,跳过真正的请求发送
| // 此功能自定义 fetcher 的话会失效
| // api.context 中包含发送请求前的上下文信息
| // 获取本地的 token
| const accessSession = Local.get(accessSessionKey);
| if (!NO_AUTH_API_LIST.includes(api.url)) {
| if (accessSession) {
| // 将 token 添加到请求报文头中
| api.headers['hswatersession'] = accessSession;
| } else {
| if (api.url !== LOGIN_URL && api.url !== TEL_LOGIN_URL) {
| handleNoAuth(api.url);
| throw '权限验证失败';
| }
| }
| }
|
| api.url = `${MAIN_URL}${api.url}`;
| return api;
| },
|
| }
| );
| });
|
| onUnmounted(()=>{
| amisInstance?.unmount();
|
| })
| </script>
| <style scoped lang="scss"></style>
|
|