af-mobile-client-vue3 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mock/modules/demo.mock.ts +20 -0
- package/package.json +1 -1
- package/src/router/routes.ts +6 -0
- package/src/services/api/common.ts +1 -1
- package/src/services/api/search.ts +10 -2
- package/src/services/restTools.ts +13 -9
- package/src/utils/http/index.ts +5 -4
- package/src/views/component/XRequestView/index.vue +185 -0
- package/src/views/component/index.vue +4 -0
- package/src/views/user/login/LoginForm.vue +3 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// https://github.com/pengzhanbo/vite-plugin-mock-dev-server
|
|
2
|
+
import { defineMock } from 'vite-plugin-mock-dev-server'
|
|
3
|
+
|
|
4
|
+
export default defineMock([
|
|
5
|
+
{
|
|
6
|
+
url: '/api/demo/post',
|
|
7
|
+
method: 'POST',
|
|
8
|
+
body: (params) => {
|
|
9
|
+
return {
|
|
10
|
+
code: 200,
|
|
11
|
+
msg: '操作成功',
|
|
12
|
+
data: {
|
|
13
|
+
...params,
|
|
14
|
+
id: Math.floor(Math.random() * 1000),
|
|
15
|
+
timestamp: new Date().toISOString(),
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
])
|
package/package.json
CHANGED
package/src/router/routes.ts
CHANGED
|
@@ -16,6 +16,7 @@ import XFormView from '@af-mobile-client-vue3/views/component/XFormView/index.vu
|
|
|
16
16
|
import XReportFormIframeView from '@af-mobile-client-vue3/views/component/XReportFormIframeView/index.vue'
|
|
17
17
|
import XReportFormView from '@af-mobile-client-vue3/views/component/XReportFormView/index.vue'
|
|
18
18
|
import XReportGridView from '@af-mobile-client-vue3/views/component/XReportGridView/index.vue'
|
|
19
|
+
import XRequestView from '@af-mobile-client-vue3/views/component/XRequestView/index.vue'
|
|
19
20
|
import XSignatureView from '@af-mobile-client-vue3/views/component/XSignatureView/index.vue'
|
|
20
21
|
import login from '@af-mobile-client-vue3/views/user/login/index.vue'
|
|
21
22
|
|
|
@@ -128,6 +129,11 @@ const routes: Array<RouteRecordRaw> = [
|
|
|
128
129
|
name: 'GridView',
|
|
129
130
|
component: GridView,
|
|
130
131
|
},
|
|
132
|
+
{
|
|
133
|
+
path: '/Component/XRequestView',
|
|
134
|
+
name: 'XRequestView',
|
|
135
|
+
component: XRequestView,
|
|
136
|
+
},
|
|
131
137
|
],
|
|
132
138
|
},
|
|
133
139
|
{
|
|
@@ -33,7 +33,7 @@ export function getConfigByName(configName: string, callback: Function, serviceN
|
|
|
33
33
|
|
|
34
34
|
export async function getConfigByNameAsync(configName: string, serviceName = import.meta.env.VITE_APP_SYSTEM_NAME): Promise<any> {
|
|
35
35
|
return new Promise((resolve, reject) => {
|
|
36
|
-
indexedDB.getByWeb(configName, `/${serviceName}/${commonApi.getConfig}`, { configName }, resolve,
|
|
36
|
+
indexedDB.getByWeb(configName, `/${serviceName}/${commonApi.getConfig}`, { configName }, resolve, null)
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { post } from '@af-mobile-client-vue3/services/restTools'
|
|
2
2
|
|
|
3
|
-
export function getUserPermissions(userid: string) {
|
|
4
|
-
|
|
3
|
+
export async function getUserPermissions(userid: string) {
|
|
4
|
+
interface permissions {
|
|
5
|
+
name: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const res = await post<permissions[]>(`/af-system/search`, {
|
|
5
9
|
source: 'this.getRights().where(row.getType()==$function$ && row.getPath($name$).indexOf($功能权限$) != -1)',
|
|
6
10
|
userid,
|
|
7
11
|
})
|
|
12
|
+
|
|
13
|
+
return res.map((row) => {
|
|
14
|
+
return row.name
|
|
15
|
+
})
|
|
8
16
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { BasicResponseModel } from '@af-mobile-client-vue3/api/user'
|
|
2
1
|
import { http } from '@af-mobile-client-vue3/utils/http'
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -6,8 +5,8 @@ import { http } from '@af-mobile-client-vue3/utils/http'
|
|
|
6
5
|
* @param url 请求地址
|
|
7
6
|
* @param params 路径参数
|
|
8
7
|
*/
|
|
9
|
-
export function get(url: string, params?: any) {
|
|
10
|
-
return http.request<
|
|
8
|
+
export function get<T = any>(url: string, params?: any): Promise<T> {
|
|
9
|
+
return http.request<T>({
|
|
11
10
|
url,
|
|
12
11
|
method: 'GET',
|
|
13
12
|
params,
|
|
@@ -19,16 +18,21 @@ export function get(url: string, params?: any) {
|
|
|
19
18
|
* @param url 请求地址
|
|
20
19
|
* @param data 请求参数
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
/**
|
|
22
|
+
* POST请求
|
|
23
|
+
* @param url 请求地址
|
|
24
|
+
* @param data 请求参数
|
|
25
|
+
*/
|
|
26
|
+
export function post<T = any>(url: string, data: any): Promise<T> {
|
|
27
|
+
return http.request <T>({
|
|
24
28
|
url,
|
|
25
29
|
method: 'POST',
|
|
26
30
|
data,
|
|
27
31
|
})
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export function postWithConfig(url: string, data: any, config: any) {
|
|
31
|
-
return http.request<
|
|
34
|
+
export function postWithConfig<T = any>(url: string, data: any, config: any): Promise<T> {
|
|
35
|
+
return http.request<T>({
|
|
32
36
|
url,
|
|
33
37
|
method: 'POST',
|
|
34
38
|
data,
|
|
@@ -42,8 +46,8 @@ export function postWithConfig(url: string, data: any, config: any) {
|
|
|
42
46
|
* @param data 查询参数
|
|
43
47
|
* @param config 额外的配置项(如自定义头信息等)
|
|
44
48
|
*/
|
|
45
|
-
export function del(url: string, data?: any, config?: any) {
|
|
46
|
-
return http.request<
|
|
49
|
+
export function del<T = any>(url: string, data?: any, config?: any): Promise<T> {
|
|
50
|
+
return http.request<T>({
|
|
47
51
|
url,
|
|
48
52
|
method: 'DELETE',
|
|
49
53
|
data,
|
package/src/utils/http/index.ts
CHANGED
|
@@ -49,16 +49,17 @@ class Http {
|
|
|
49
49
|
Http.axiosInstance.interceptors.response.use(
|
|
50
50
|
async (response: AxiosResponse) => {
|
|
51
51
|
const compatible = import.meta.env.VITE_APP_COMPATIBLE
|
|
52
|
-
if (compatible !== 'V4')
|
|
52
|
+
if (compatible !== 'V4') {
|
|
53
53
|
return response.data
|
|
54
|
+
}
|
|
54
55
|
// 与后端协定的返回字段
|
|
55
56
|
const { code, msg, data } = response.data
|
|
56
57
|
// 临时向v3请求上传服务,因为没有code,未来会改
|
|
57
|
-
if (code === undefined
|
|
58
|
+
if (code === undefined) {
|
|
58
59
|
return response.data
|
|
60
|
+
}
|
|
59
61
|
// 判断请求是否成功
|
|
60
|
-
const isSuccess
|
|
61
|
-
= code === ResultEnum.SUCCESS
|
|
62
|
+
const isSuccess = code === ResultEnum.SUCCESS
|
|
62
63
|
if (isSuccess) {
|
|
63
64
|
return data
|
|
64
65
|
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { queryProse } from '@af-mobile-client-vue3/api/mock'
|
|
3
|
+
import { post } from '@af-mobile-client-vue3/services/restTools'
|
|
4
|
+
import { showToast, Button as VanButton, Cell as VanCell, CellGroup as VanCellGroup } from 'vant'
|
|
5
|
+
import { reactive, ref } from 'vue'
|
|
6
|
+
import { useRouter } from 'vue-router'
|
|
7
|
+
|
|
8
|
+
// 路由
|
|
9
|
+
const router = useRouter()
|
|
10
|
+
|
|
11
|
+
// 数据定义
|
|
12
|
+
const requestTypes = ref('GET, POST, DELETE')
|
|
13
|
+
const getResult = ref('')
|
|
14
|
+
const postResult = ref('')
|
|
15
|
+
const postData = reactive({
|
|
16
|
+
name: '',
|
|
17
|
+
value: '',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// 返回上一页
|
|
21
|
+
function onClickLeft() {
|
|
22
|
+
router.back()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 发送GET请求示例
|
|
26
|
+
async function handleGetRequest() {
|
|
27
|
+
try {
|
|
28
|
+
// 这里使用项目中的模拟API
|
|
29
|
+
const result = await queryProse()
|
|
30
|
+
getResult.value = JSON.stringify(result, null, 2)
|
|
31
|
+
showToast('请求成功')
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error('GET请求失败:', error)
|
|
35
|
+
showToast('请求失败')
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 定义请求数据类型
|
|
40
|
+
interface RequestData {
|
|
41
|
+
name: string
|
|
42
|
+
value: string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 定义返回结果类型
|
|
46
|
+
interface ResponseData {
|
|
47
|
+
code: number
|
|
48
|
+
msg: string
|
|
49
|
+
data: any
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 发送POST请求示例
|
|
53
|
+
async function handlePostRequest() {
|
|
54
|
+
try {
|
|
55
|
+
// 这里演示使用通用post方法发送请求
|
|
56
|
+
// 使用泛型指定返回类型
|
|
57
|
+
const result = await post<ResponseData>('/api/demo/post', {
|
|
58
|
+
name: '测试',
|
|
59
|
+
value: '测试',
|
|
60
|
+
})
|
|
61
|
+
postResult.value = JSON.stringify(result, null, 2)
|
|
62
|
+
showToast('请求成功')
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('POST请求失败:', error)
|
|
66
|
+
showToast('请求失败')
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 类型定义展示
|
|
71
|
+
const typeDefinitions = `
|
|
72
|
+
|
|
73
|
+
// 使用泛型扩展特定业务数据类型
|
|
74
|
+
import { get } from '@af-mobile-client-vue3/services/restTools'
|
|
75
|
+
|
|
76
|
+
interface UserInfo {
|
|
77
|
+
id: string
|
|
78
|
+
name: string
|
|
79
|
+
roles: string[]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 调用示例
|
|
83
|
+
const userInfo = await get<UserInfo>('/api/user/info')
|
|
84
|
+
// userInfo 类型为 UserInfo,而非 BasicResponseModel<UserInfo>
|
|
85
|
+
// 不用使用 userInfo.data 获取数据
|
|
86
|
+
// 直接使用 userInfo 即可
|
|
87
|
+
`.trim()
|
|
88
|
+
</script>
|
|
89
|
+
|
|
90
|
+
<template>
|
|
91
|
+
<div class="request-view">
|
|
92
|
+
<div class="container">
|
|
93
|
+
<VanCellGroup title="API请求演示">
|
|
94
|
+
<VanCell title="基本请求类型" :value="requestTypes" />
|
|
95
|
+
|
|
96
|
+
<!-- GET请求部分 -->
|
|
97
|
+
<div class="request-section">
|
|
98
|
+
<h3>GET请求示例</h3>
|
|
99
|
+
<VanButton type="primary" size="small" @click="handleGetRequest">
|
|
100
|
+
发送GET请求
|
|
101
|
+
</VanButton>
|
|
102
|
+
<div v-if="getResult" class="result-box">
|
|
103
|
+
<h4>响应结果:</h4>
|
|
104
|
+
<pre>{{ getResult }}</pre>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
|
|
108
|
+
<!-- POST请求部分 -->
|
|
109
|
+
<div class="request-section">
|
|
110
|
+
<h3>POST请求示例</h3>
|
|
111
|
+
|
|
112
|
+
<VanButton type="primary" size="small" @click="handlePostRequest">
|
|
113
|
+
发送POST请求
|
|
114
|
+
</VanButton>
|
|
115
|
+
<div v-if="postResult" class="result-box">
|
|
116
|
+
<h4>响应结果:</h4>
|
|
117
|
+
<pre>{{ postResult }}</pre>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
|
|
121
|
+
<!-- 类型定义说明 -->
|
|
122
|
+
<div class="code-section">
|
|
123
|
+
<h3>类型定义</h3>
|
|
124
|
+
<pre>{{ typeDefinitions }}</pre>
|
|
125
|
+
</div>
|
|
126
|
+
</VanCellGroup>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</template>
|
|
130
|
+
|
|
131
|
+
<style scoped>
|
|
132
|
+
.request-view {
|
|
133
|
+
height: 100%;
|
|
134
|
+
display: flex;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.container {
|
|
139
|
+
flex: 1;
|
|
140
|
+
padding: 16px;
|
|
141
|
+
overflow-y: auto;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.request-section {
|
|
145
|
+
margin: 16px 0;
|
|
146
|
+
padding: 16px;
|
|
147
|
+
background-color: #f7f8fa;
|
|
148
|
+
border-radius: 8px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.result-box {
|
|
152
|
+
margin-top: 16px;
|
|
153
|
+
padding: 12px;
|
|
154
|
+
background-color: #ffffff;
|
|
155
|
+
border-radius: 4px;
|
|
156
|
+
border: 1px solid #ebedf0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
pre {
|
|
160
|
+
white-space: pre-wrap;
|
|
161
|
+
word-break: break-all;
|
|
162
|
+
font-size: 12px;
|
|
163
|
+
font-family: Consolas, Monaco, monospace;
|
|
164
|
+
background-color: #f5f7fa;
|
|
165
|
+
padding: 8px;
|
|
166
|
+
border-radius: 4px;
|
|
167
|
+
overflow-x: auto;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.code-section {
|
|
171
|
+
margin: 16px 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
h3 {
|
|
175
|
+
margin: 0 0 12px;
|
|
176
|
+
font-size: 15px;
|
|
177
|
+
color: #323233;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
h4 {
|
|
181
|
+
margin: 0 0 8px;
|
|
182
|
+
font-size: 14px;
|
|
183
|
+
color: #323233;
|
|
184
|
+
}
|
|
185
|
+
</style>
|
|
@@ -158,7 +158,7 @@ function closeWindows() {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
function afterGeneral(result) {
|
|
161
|
+
async function afterGeneral(result) {
|
|
162
162
|
const user: UserInfo = {
|
|
163
163
|
id: result.id,
|
|
164
164
|
username: result.ename,
|
|
@@ -171,7 +171,8 @@ function afterGeneral(result) {
|
|
|
171
171
|
userState.setUserInfo(user)
|
|
172
172
|
// 如果result中没有返回 权限 需要主动获取权限列表
|
|
173
173
|
if (!result.permissions) {
|
|
174
|
-
result.permissions = getUserPermissions(result.id)
|
|
174
|
+
result.permissions = await getUserPermissions(result.id)
|
|
175
|
+
console.log(result.permissions, '====')
|
|
175
176
|
}
|
|
176
177
|
userState.setPermissions(result.permissions)
|
|
177
178
|
userState.setRoles([{ id: 'admin', operation: ['add', 'edit', 'delete'] }])
|