af-mobile-client-vue3 1.0.98 → 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.
@@ -0,0 +1,154 @@
1
+ // 导入proj控件
2
+ import * as proj from 'ol/proj'
3
+
4
+ function forEachPoint(func) {
5
+ return function (input, opt_output, opt_dimension) {
6
+ const len = input.length
7
+
8
+ const dimension = opt_dimension || 2
9
+ let output
10
+
11
+ if (opt_output) {
12
+ output = opt_output
13
+ }
14
+ else {
15
+ if (dimension !== 2) {
16
+ output = input.slice()
17
+ }
18
+ else {
19
+ output = [len]
20
+ }
21
+ }
22
+ for (let offset = 0; offset < len; offset += dimension) {
23
+ func(input, output, offset)
24
+ }
25
+ return output
26
+ }
27
+ }
28
+
29
+ const gcj02 = {}
30
+ const PI = Math.PI
31
+ const AXIS = 6378245.0
32
+ // eslint-disable-next-line no-loss-of-precision
33
+ const OFFSET = 0.00669342162296594323 // (a^2 - b^2) / a^2
34
+
35
+ function delta(wgLon, wgLat) {
36
+ let dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
37
+ let dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
38
+ const radLat = (wgLat / 180.0) * PI
39
+ let magic = Math.sin(radLat)
40
+ magic = 1 - OFFSET * magic * magic
41
+ const sqrtMagic = Math.sqrt(magic)
42
+ dLat = (dLat * 180.0) / (((AXIS * (1 - OFFSET)) / (magic * sqrtMagic)) * PI)
43
+ dLon = (dLon * 180.0) / ((AXIS / sqrtMagic) * Math.cos(radLat) * PI)
44
+ return [dLon, dLat]
45
+ }
46
+
47
+ function outOfChina(lon, lat) {
48
+ if (lon < 72.004 || lon > 137.8347) {
49
+ return true
50
+ }
51
+ return lat < 0.8293 || lat > 55.8271
52
+ }
53
+
54
+ function transformLat(x, y) {
55
+ let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
56
+ ret += ((20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0) / 3.0
57
+ ret += ((20.0 * Math.sin(y * PI) + 40.0 * Math.sin((y / 3.0) * PI)) * 2.0) / 3.0
58
+ ret += ((160.0 * Math.sin((y / 12.0) * PI) + 320 * Math.sin((y * PI) / 30.0)) * 2.0) / 3.0
59
+ return ret
60
+ }
61
+
62
+ function transformLon(x, y) {
63
+ let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
64
+ ret += ((20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0) / 3.0
65
+ ret += ((20.0 * Math.sin(x * PI) + 40.0 * Math.sin((x / 3.0) * PI)) * 2.0) / 3.0
66
+ ret += ((150.0 * Math.sin((x / 12.0) * PI) + 300.0 * Math.sin((x / 30.0) * PI)) * 2.0) / 3.0
67
+ return ret
68
+ }
69
+
70
+ gcj02.toWGS84 = forEachPoint((input, output, offset) => {
71
+ let lng = input[offset]
72
+ let lat = input[offset + 1]
73
+ if (!outOfChina(lng, lat)) {
74
+ const deltaD = delta(lng, lat)
75
+ lng = lng - deltaD[0] // 改回减法
76
+ lat = lat - deltaD[1] // 改回减法
77
+ }
78
+ output[offset] = lng
79
+ output[offset + 1] = lat
80
+ })
81
+
82
+ gcj02.fromWGS84 = forEachPoint((input, output, offset) => {
83
+ let lng = input[offset]
84
+ let lat = input[offset + 1]
85
+ if (!outOfChina(lng, lat)) {
86
+ const deltaD = delta(lng, lat)
87
+ lng = lng + deltaD[0] // 改回加法
88
+ lat = lat + deltaD[1] // 改回加法
89
+ }
90
+ output[offset] = lng
91
+ output[offset + 1] = lat
92
+ })
93
+
94
+ const sphericalMercator = {}
95
+ const RADIUS = 6378137
96
+ const MAX_LATITUDE = 85.0511287798
97
+ const RAD_PER_DEG = Math.PI / 180
98
+
99
+ sphericalMercator.forward = forEachPoint((input, output, offset) => {
100
+ const lat = Math.max(Math.min(MAX_LATITUDE, input[offset + 1]), -MAX_LATITUDE)
101
+ const sin = Math.sin(lat * RAD_PER_DEG)
102
+ output[offset] = RADIUS * input[offset] * RAD_PER_DEG
103
+ output[offset + 1] = (RADIUS * Math.log((1 + sin) / (1 - sin))) / 2
104
+ })
105
+
106
+ sphericalMercator.inverse = forEachPoint((input, output, offset) => {
107
+ output[offset] = input[offset] / RADIUS / RAD_PER_DEG
108
+ output[offset + 1] = (2 * Math.atan(Math.exp(input[offset + 1] / RADIUS)) - Math.PI / 2) / RAD_PER_DEG
109
+ })
110
+
111
+ const projzh = {}
112
+
113
+ projzh.ll2gmerc = function (input, opt_output, opt_dimension) {
114
+ const output = gcj02.toWGS84(input, opt_output, opt_dimension) // 改用 toWGS84
115
+ return projzh.ll2smerc(output, output, opt_dimension)
116
+ }
117
+
118
+ projzh.gmerc2ll = function (input, opt_output, opt_dimension) {
119
+ const output = projzh.smerc2ll(input, input, opt_dimension)
120
+ return gcj02.fromWGS84(output, opt_output, opt_dimension) // 改用 fromWGS84
121
+ }
122
+
123
+ // smerc2gmerc 需要修改
124
+
125
+ projzh.smerc2gmerc = function (input, opt_output, opt_dimension) {
126
+ let output = projzh.smerc2ll(input, input, opt_dimension)
127
+ output = gcj02.toWGS84(output, output, opt_dimension) // 这里应该用 toWGS84
128
+ return projzh.ll2smerc(output, output, opt_dimension)
129
+ }
130
+
131
+ // gmerc2smerc 需要修改
132
+
133
+ projzh.gmerc2smerc = function (input, opt_output, opt_dimension) {
134
+ let output = projzh.smerc2ll(input, input, opt_dimension)
135
+ output = gcj02.fromWGS84(output, output, opt_dimension) // 这里应该用 fromWGS84
136
+ return projzh.ll2smerc(output, output, opt_dimension)
137
+ }
138
+
139
+ projzh.ll2smerc = sphericalMercator.forward
140
+ projzh.smerc2ll = sphericalMercator.inverse
141
+
142
+ // 定义WGS84转GCJ02的投影
143
+ const extent = [-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]
144
+ export const wgs84ToGcj02Projection = new proj.Projection({
145
+ code: 'WGS84-TO-GCJ02',
146
+ extent,
147
+ units: 'm',
148
+ })
149
+
150
+ // 添加投影和转换方法
151
+ proj.addProjection(wgs84ToGcj02Projection)
152
+ // 注意这里转换方法的顺序与原来相反
153
+ proj.addCoordinateTransforms('EPSG:4326', wgs84ToGcj02Projection, projzh.ll2gmerc, projzh.gmerc2ll)
154
+ proj.addCoordinateTransforms('EPSG:3857', wgs84ToGcj02Projection, projzh.smerc2gmerc, projzh.gmerc2smerc)
@@ -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, reject)
36
+ indexedDB.getByWeb(configName, `/${serviceName}/${commonApi.getConfig}`, { configName }, resolve, null)
37
37
  })
38
38
  }
39
39
 
@@ -0,0 +1,16 @@
1
+ import { post } from '@af-mobile-client-vue3/services/restTools'
2
+
3
+ export async function getUserPermissions(userid: string) {
4
+ interface permissions {
5
+ name: string
6
+ }
7
+
8
+ const res = await post<permissions[]>(`/af-system/search`, {
9
+ source: 'this.getRights().where(row.getType()==$function$ && row.getPath($name$).indexOf($功能权限$) != -1)',
10
+ userid,
11
+ })
12
+
13
+ return res.map((row) => {
14
+ return row.name
15
+ })
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<BasicResponseModel>({
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
- export function post(url: string, data: any) {
23
- return http.request<BasicResponseModel>({
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<BasicResponseModel>({
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<BasicResponseModel>({
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,
@@ -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 && response.data.id !== 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>
@@ -24,7 +24,11 @@ const list = ref([
24
24
  },
25
25
  {
26
26
  name: 'XForm 表单',
27
- to: '/Component/XFormView/1/debug',
27
+ to: '/Component/XFormView/1/debug?configName=hiddenTroubleFollowForm&serviceName=af-linepatrol&mode=新增',
28
+ },
29
+ {
30
+ name: 'XFormGroup 表单组',
31
+ to: '/Component/XFormGroupView',
28
32
  },
29
33
  {
30
34
  name: '操作卡手机端',
@@ -46,6 +50,14 @@ const list = ref([
46
50
  name: 'XFormAppraise 表单',
47
51
  to: '/Component/XFormAppraiseView/2/debug',
48
52
  },
53
+ {
54
+ name: 'XOlmap 地图组件',
55
+ to: '/Component/XOlMapView',
56
+ },
57
+ {
58
+ name: '请求示例',
59
+ to: '/Component/XRequestView',
60
+ },
49
61
  ])
50
62
 
51
63
  function cleanConfigCache() {
@@ -3,12 +3,25 @@ import type { UserInfo } from '@af-mobile-client-vue3/stores/modules/user'
3
3
  import type { FormInstance } from 'vant'
4
4
  import { LoginStateEnum, useFormRules, useLoginState } from '@af-mobile-client-vue3/hooks/useLogin'
5
5
  import GetAppDataService from '@af-mobile-client-vue3/plugins/AppData'
6
+ import { getUserPermissions } from '@af-mobile-client-vue3/services/api/search'
6
7
  import { useSettingStore } from '@af-mobile-client-vue3/stores/modules/setting'
7
8
  import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
8
9
  import { indexedDB } from '@af-mobile-client-vue3/utils/indexedDB'
9
10
  import { funcToRouter, loadRoutes } from '@af-mobile-client-vue3/utils/routerUtil'
10
11
  import { isWechat } from '@af-mobile-client-vue3/utils/wechatUtil'
11
- import { closeToast, showDialog, showFailToast, Switch, Button as VanButton, Col as VanCol, Field as VanField, Form as VanForm, Icon as VanIcon, Loading as VanLoading, Row as VanRow } from 'vant'
12
+ import {
13
+ closeToast,
14
+ showDialog,
15
+ showFailToast,
16
+ Switch,
17
+ Button as VanButton,
18
+ Col as VanCol,
19
+ Field as VanField,
20
+ Form as VanForm,
21
+ Icon as VanIcon,
22
+ Loading as VanLoading,
23
+ Row as VanRow,
24
+ } from 'vant'
12
25
  import { computed, inject, onBeforeMount, onMounted, reactive, ref, unref } from 'vue'
13
26
  import { useRoute, useRouter } from 'vue-router'
14
27
  import 'vant/lib/switch/index.css'
@@ -41,13 +54,12 @@ onBeforeMount(async () => {
41
54
  try {
42
55
  wxloading.value = true
43
56
  if (route.query.code && route.query.state) {
44
- const res: any = await userState.loginUnified({
57
+ const data = await userState.loginUnified({
45
58
  unifiedCode: `${route.query.code}`,
46
59
  tenantName: `${route.query.state}`,
47
60
  loginMode: 'wechat',
48
61
  resourceName: setting.getSetting()?.routerName || '智慧手机',
49
62
  })
50
- const data = res
51
63
  login.f = data
52
64
  await Promise.all([GetAppDataService.load()])
53
65
  const loginInfo = {
@@ -146,7 +158,7 @@ function closeWindows() {
146
158
  }
147
159
  }
148
160
 
149
- function afterGeneral(result) {
161
+ async function afterGeneral(result) {
150
162
  const user: UserInfo = {
151
163
  id: result.id,
152
164
  username: result.ename,
@@ -157,7 +169,12 @@ function afterGeneral(result) {
157
169
  rolestr: result.rolestr,
158
170
  }
159
171
  userState.setUserInfo(user)
160
- userState.setPermissions([{ id: 'queryForm', operation: ['add', 'edit'] }])
172
+ // 如果result中没有返回 权限 需要主动获取权限列表
173
+ if (!result.permissions) {
174
+ result.permissions = await getUserPermissions(result.id)
175
+ console.log(result.permissions, '====')
176
+ }
177
+ userState.setPermissions(result.permissions)
161
178
  userState.setRoles([{ id: 'admin', operation: ['add', 'edit', 'delete'] }])
162
179
  // 加载路由
163
180
  loadRoutes(funcToRouter(user.functions))