wui-components-v2 1.1.93 → 1.1.95

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/api/core/index.ts CHANGED
@@ -12,7 +12,7 @@ interface RequestOptions {
12
12
  url: string
13
13
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT'
14
14
  data?: any
15
- header?: any
15
+ header?: Record<string, string>
16
16
  timeout?: number
17
17
  }
18
18
 
@@ -22,6 +22,7 @@ function request(options: RequestOptions): Promise<any> {
22
22
  const token = uni.getStorageSync('TOKEN') || uni.getStorageSync('token') || ''
23
23
  const hydrocarbonClient = uni.getStorageSync('HYDROCARBON_CLIENT') || ''
24
24
  const applicationToken = uni.getStorageSync('HYDROCARBON_APPLICATION_TOKEN') || ''
25
+
25
26
  return new Promise((resolve, reject) => {
26
27
  // 设置默认值
27
28
  const defaultOptions = {
@@ -50,23 +51,60 @@ function request(options: RequestOptions): Promise<any> {
50
51
 
51
52
  uni.request({
52
53
  ...requestOptions,
53
- success: (res: any) => {
54
- // 可以根据实际业务需求调整这里的判断条件
55
- if (res.statusCode >= 200 && res.statusCode < 300) {
56
- if (res.data.status === 'error') {
57
- uni.showToast({ title: res.data.message, icon: 'none' })
58
- uni.removeStorageSync('token')
59
- reject(res)
60
- return
61
- }
62
- resolve(res.data)
63
- } else {
54
+ success: (res: UniApp.RequestSuccessCallbackResult) => {
55
+ console.log('res111111', res)
56
+ const { statusCode, data } = res
57
+
58
+ // 细分HTTP状态码错误处理,移除200-300区间整体判断
59
+ if (statusCode === 401) {
60
+ uni.showToast({ title: '登录身份已失效,请重新登录', icon: 'none' })
61
+ uni.removeStorageSync('token')
62
+ uni.removeStorageSync('TOKEN')
63
+ reject(res)
64
+ uni.reLaunch({ url: '/pages/login/index' })
65
+ return
66
+ }
67
+ if (statusCode === 403) {
68
+ uni.showToast({ title: '当前账号无访问权限', icon: 'none' })
69
+ reject(res)
70
+ return
71
+ }
72
+ if (statusCode === 404) {
73
+ uni.showToast({ title: '请求接口不存在', icon: 'none' })
74
+ reject(res)
75
+ return
76
+ }
77
+ if (statusCode >= 500) {
78
+ uni.showToast({ title: '服务器异常,请稍后重试', icon: 'none' })
64
79
  reject(res)
80
+ return
65
81
  }
82
+ if (statusCode < 200 || statusCode >= 300) {
83
+ uni.showToast({ title: `请求异常 ${statusCode}`, icon: 'none' })
84
+ reject(res)
85
+ return
86
+ }
87
+
88
+ // 业务状态错误判断
89
+ if (data.status === 'error') {
90
+ uni.showToast({ title: data.message || '操作失败', icon: 'none' })
91
+ uni.removeStorageSync('token')
92
+ uni.removeStorageSync('TOKEN')
93
+ reject(res)
94
+ return
95
+ }
96
+
97
+ // 全部校验通过,返回原始业务data
98
+ resolve(data)
66
99
  },
67
- fail: (err: any) => {
100
+ fail: (err: UniApp.RequestFailCallbackResult) => {
101
+ uni.showToast({ title: '网络请求失败,请检查网络或接口地址', icon: 'none' })
68
102
  reject(err)
69
103
  },
104
+ // 增加complete统一处理(可选,如需loading可在这里隐藏)
105
+ complete: () => {
106
+ // uni.hideLoading()
107
+ },
70
108
  })
71
109
  })
72
110
  }
@@ -30,6 +30,11 @@ const props = defineProps<{
30
30
  detailButtonHandle?: (data: Entities) => void
31
31
  buttonDeleteAction?: { [key: string]: any }
32
32
  buttonEditAction?: { [key: string]: any }
33
+ /**
34
+ * 是否显示操作按钮区域(morebutns / 编辑 / 删除)。
35
+ * 不传或为 true 时显示;传 false 时整段隐藏。
36
+ */
37
+ isShowAction?: boolean
33
38
  }>()
34
39
  const toast = useGlobalToast()
35
40
  const message = useGlobalMessage()
@@ -43,20 +48,20 @@ const router = useRouter()
43
48
  // rowActions按钮
44
49
  const anctions = computed(() => {
45
50
  const rowActions = props.rowActions || []
46
- console.log([...rowActions.filter(isShowAction)], 1111111111111111)
47
- return [...rowActions.filter(isShowAction)]
51
+ console.log([...rowActions.filter(isActionVisible)], 1111111111111111)
52
+ return [...rowActions.filter(isActionVisible)]
48
53
  })
49
54
 
50
55
  // raction按钮
51
56
  const ractions = computed(() => {
52
57
  const list = props.ractions || []
53
- return list.filter(isShowAction)
58
+ return list.filter(isActionVisible)
54
59
  })
55
60
 
56
61
  // actions按钮
57
62
  const actions = computed(() => {
58
63
  const actions = props.actions || []
59
- return [...actions.filter(isShowAction)]
64
+ return [...actions.filter(isActionVisible)]
60
65
  })
61
66
 
62
67
  // 跳转编辑页面
@@ -115,7 +120,7 @@ function detail() {
115
120
  }
116
121
 
117
122
  // 判断按钮是否满足条件显示
118
- function isShowAction(item?: { preposes?: Fields[] }) {
123
+ function isActionVisible(item?: { preposes?: Fields[] }) {
119
124
  if (item?.preposes?.length) {
120
125
  return item.preposes.every((prepose: Fields) => {
121
126
  // 判断字段值是否满足要求
@@ -252,23 +257,25 @@ console.log(props, '3333333333333')
252
257
  </wd-button>
253
258
  </view> -->
254
259
 
255
- <template v-for="subitem in morebutns" :key="subitem.id">
256
- <wd-button
257
- v-if="isShowAction(subitem)"
258
- plain
259
- size="small"
260
- @click="
261
- () => {
262
- select({ item: subitem })
263
- }
264
- "
265
- >
266
- {{ subitem.title }}
267
- </wd-button>
260
+ <template v-if="isShowAction !== false">
261
+ <template v-for="subitem in morebutns" :key="subitem.id">
262
+ <wd-button
263
+ v-if="isActionVisible(subitem)"
264
+ plain
265
+ size="small"
266
+ @click="
267
+ () => {
268
+ select({ item: subitem })
269
+ }
270
+ "
271
+ >
272
+ {{ subitem.title }}
273
+ </wd-button>
274
+ </template>
268
275
  </template>
269
276
 
270
277
  <wd-button
271
- v-if="props.item.buttons.includes('dtmplEdit') && isShowAction(props.buttonEditAction)"
278
+ v-if="isShowAction !== false && props.item.buttons.includes('dtmplEdit') && isActionVisible(props.buttonEditAction)"
272
279
  size="small"
273
280
  @click="edit()"
274
281
  >
@@ -276,7 +283,7 @@ console.log(props, '3333333333333')
276
283
  </wd-button>
277
284
  <wd-button v-if="props.item.buttons.includes('detail')" size="small" type="info" @click="detail()">详情</wd-button>
278
285
  <wd-button
279
- v-if="props.item.buttons.includes('singleDelete') && isShowAction(props.buttonDeleteAction)"
286
+ v-if="isShowAction !== false && props.item.buttons.includes('singleDelete') && isActionVisible(props.buttonDeleteAction)"
280
287
  size="small"
281
288
  type="danger"
282
289
  @click="del()"
@@ -16,6 +16,7 @@ defineOptions({
16
16
  name: 'WuiList',
17
17
  })
18
18
  defineProps<{
19
+ isShowAction?: boolean
19
20
  detailButtonHandle?: (data: Entities) => void
20
21
  /**
21
22
  * 折叠前展示的数据条数,透传给 foldCard。
@@ -241,6 +242,7 @@ function tabSearchClick(data: any) {
241
242
  :code="item.code"
242
243
  :page-type="pageType"
243
244
  :data="item"
245
+ :is-show-action="isShowAction"
244
246
  />
245
247
  </template>
246
248
  </productCard>
@@ -279,6 +281,7 @@ function tabSearchClick(data: any) {
279
281
  :data="item"
280
282
  :button-delete-action="config.buttonDeleteAction"
281
283
  :button-edit-action="config.buttonEditAction"
284
+ :is-show-action="isShowAction"
282
285
  />
283
286
  </template>
284
287
  </foldCard2>
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
3
3
  import { enums, listData, pageConfig, pageKey } from '../../api/page'
4
- import foldCard2 from '../fold-card2/fold-card2.vue'
4
+ import foldCard from '../fold-card/fold-card.vue'
5
5
  import Search from '../search/search.vue'
6
6
  import type { Config, Entities, Enums, FoldCardModel } from '../../type'
7
7
  import { useGlobalToast } from '../../composables/useGlobalToast'
@@ -475,7 +475,7 @@ console.log(props, 'props')
475
475
  <slot name="top" />
476
476
  </template>
477
477
 
478
- <foldCard2
478
+ <foldCard
479
479
  v-for="(item, index) in datas"
480
480
  :key="item.code"
481
481
  :index="index"
@@ -496,7 +496,7 @@ console.log(props, 'props')
496
496
  :type="checkboxType"
497
497
  />
498
498
  </template>
499
- </foldCard2>
499
+ </foldCard>
500
500
 
501
501
  <template #bottom>
502
502
  <view class="popup-footer flex justify-center gap-4 p-4 border-t border-gray-200">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wui-components-v2",
3
- "version": "1.1.93",
3
+ "version": "1.1.95",
4
4
  "description": "wui 组件库",
5
5
  "author": "wgxshh",
6
6
  "license": "MIT",