@tplc/business 0.7.75 → 0.7.76

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/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.7.76](https://gitlab888.30jia.com.cn/tourism-front/zero-code-pro/compare/v0.7.75...v0.7.76) (2026-01-18)
6
+
7
+
8
+ ### ♻️ Code Refactoring | 代码重构
9
+
10
+ * **types:** remove unused properties from LcbGapProps and LcbAreaProps, enhance LcbBlockProps with additional positioning attributes ([3e5dd22](https://gitlab888.30jia.com.cn/tourism-front/zero-code-pro/commit/3e5dd22dca2a854fc7760ef7f824c3b23a1c59db))
11
+
12
+
13
+ ### ✨ Features | 新功能
14
+
15
+ * **lcb-form:** enhance form component with customizable title styles and conditional submit button visibility ([6b24629](https://gitlab888.30jia.com.cn/tourism-front/zero-code-pro/commit/6b246290e9a8a066353b461fd4cfdba62477c388))
16
+
5
17
  ### [0.7.75](https://gitlab888.30jia.com.cn/tourism-front/zero-code-pro/compare/v0.7.74...v0.7.75) (2026-01-18)
6
18
 
7
19
 
@@ -0,0 +1,192 @@
1
+ # FormKey 功能使用说明
2
+
3
+ ## 功能概述
4
+
5
+ 该功能允许 `lcb-form` 组件将表单数据通过 `formKey` 注册到页面上下文 (`PAGE_PROVIDE_KEY`) 中,然后 `lcb-button` 组件可以通过指定 `formKeys` 在发送请求时自动携带对应表单的数据。
6
+
7
+ ## 使用方法
8
+
9
+ ### 1. 在 lcb-form 中设置 formKey
10
+
11
+ ```vue
12
+ <lcb-form
13
+ :fields="formFields"
14
+ formKey="userForm"
15
+ v-model="formData"
16
+ />
17
+ ```
18
+
19
+ - `formKey`: 表单的唯一标识符,可以是任意字符串
20
+ - 设置 `formKey` 后,表单数据会自动注册到 `PAGE_PROVIDE_KEY` 中
21
+
22
+ ### 2. 在 lcb-button 中关联 formKeys
23
+
24
+ #### 方式一:直接在 button 上设置 formKeys
25
+
26
+ ```vue
27
+ <lcb-button
28
+ text="提交"
29
+ :formKeys="['userForm']"
30
+ :action="{
31
+ jumpType: 17,
32
+ requestInfo: {
33
+ requestUrl: '/api/user/submit',
34
+ requestParams: {
35
+ type: 'create'
36
+ }
37
+ }
38
+ }"
39
+ />
40
+ ```
41
+
42
+ #### 方式二:在 action 的 requestInfo 中设置 formKeys
43
+
44
+ ```vue
45
+ <lcb-button
46
+ text="提交"
47
+ :action="{
48
+ jumpType: 17,
49
+ requestInfo: {
50
+ requestUrl: '/api/user/submit',
51
+ requestParams: {
52
+ type: 'create'
53
+ },
54
+ formKeys: ['userForm']
55
+ }
56
+ }"
57
+ />
58
+ ```
59
+
60
+ ### 3. 关联多个表单
61
+
62
+ 一个按钮可以同时关联多个表单:
63
+
64
+ ```vue
65
+ <lcb-button
66
+ text="提交"
67
+ :formKeys="['userForm', 'addressForm']"
68
+ :action="{
69
+ jumpType: 17,
70
+ requestInfo: {
71
+ requestUrl: '/api/user/submit',
72
+ requestParams: {
73
+ type: 'create'
74
+ }
75
+ }
76
+ }"
77
+ />
78
+ ```
79
+
80
+ 或在 requestInfo 中:
81
+
82
+ ```vue
83
+ <lcb-button
84
+ text="提交"
85
+ :action="{
86
+ jumpType: 17,
87
+ requestInfo: {
88
+ requestUrl: '/api/user/submit',
89
+ requestParams: {
90
+ type: 'create'
91
+ },
92
+ formKeys: ['userForm', 'addressForm']
93
+ }
94
+ }"
95
+ />
96
+ ```
97
+
98
+ ## 数据合并规则
99
+
100
+ 当按钮发送请求时,数据合并顺序为:
101
+
102
+ 1. 先使用 `requestParams` 中的原始参数
103
+ 2. 然后依次合并 `formKeys` 对应的表单数据
104
+ 3. **formKeys 的数据会覆盖 requestParams 中的同名字段**
105
+
106
+ ### 示例
107
+
108
+ 假设有以下配置:
109
+
110
+ ```javascript
111
+ // 表单数据
112
+ formData = {
113
+ name: '张三',
114
+ age: 25
115
+ }
116
+
117
+ // requestParams
118
+ requestParams = {
119
+ type: 'create',
120
+ age: 20
121
+ }
122
+ ```
123
+
124
+ 最终发送的请求参数为:
125
+
126
+ ```javascript
127
+ {
128
+ type: 'create', // 来自 requestParams
129
+ name: '张三', // 来自 formKeys
130
+ age: 25 // 来自 formKeys,覆盖了 requestParams 中的 age: 20
131
+ }
132
+ ```
133
+
134
+ ## 完整示例
135
+
136
+ ```vue
137
+ <template>
138
+ <view>
139
+ <!-- 用户信息表单 -->
140
+ <lcb-form
141
+ :fields="userFields"
142
+ formKey="userForm"
143
+ v-model="userData"
144
+ />
145
+
146
+ <!-- 地址信息表单 -->
147
+ <lcb-form
148
+ :fields="addressFields"
149
+ formKey="addressForm"
150
+ v-model="addressData"
151
+ />
152
+
153
+ <!-- 提交按钮,同时提交两个表单的数据 -->
154
+ <lcb-button
155
+ text="提交"
156
+ :formKeys="['userForm', 'addressForm']"
157
+ :action="{
158
+ jumpType: 17,
159
+ requestInfo: {
160
+ requestUrl: '/api/user/submit',
161
+ requestParams: {
162
+ submitType: 'complete'
163
+ }
164
+ }
165
+ }"
166
+ />
167
+ </view>
168
+ </template>
169
+
170
+ <script setup>
171
+ import { ref } from 'vue'
172
+
173
+ const userData = ref({})
174
+ const addressData = ref({})
175
+
176
+ const userFields = [
177
+ // ... 表单字段配置
178
+ ]
179
+
180
+ const addressFields = [
181
+ // ... 表单字段配置
182
+ ]
183
+ </script>
184
+ ```
185
+
186
+ ## 注意事项
187
+
188
+ 1. **无需表单验证**: 按钮发送请求时不会触发表单验证,直接提交数据
189
+ 2. **formKey 必须唯一**: 在同一个页面中,不同表单的 `formKey` 应该保持唯一
190
+ 3. **数据覆盖**: formKeys 的数据会覆盖 requestParams 中的同名字段
191
+ 4. **formKeys 优先级**: 如果 button 和 requestInfo 中都设置了 formKeys,button 的 formKeys 会传递给 requestInfo
192
+ 5. **数组类型**: formKeys 统一使用数组类型,即使只绑定一个表单也需要使用数组:`['formKey']`
@@ -227,8 +227,25 @@ const onActionClick = async () => {
227
227
  }
228
228
  break
229
229
  case '17':
230
- if ('requestInfo' in props && props.requestInfo)
231
- await uni.$lcb.http.post(props.requestInfo.requestUrl, props.requestInfo.requestParams)
230
+ if ('requestInfo' in props && props.requestInfo) {
231
+ // 准备请求参数
232
+ let finalParams = { ...props.requestInfo.requestParams }
233
+
234
+ // 如果有 formKeys,从 PAGE_PROVIDE_KEY 中获取表单数据并合并(formKeys 数据覆盖 requestParams)
235
+ if (props.requestInfo.formKeys && Array.isArray(props.requestInfo.formKeys)) {
236
+ props.requestInfo.formKeys.forEach((key) => {
237
+ const formData = pageInfo.value?.[key]
238
+ if (formData) {
239
+ finalParams = {
240
+ ...finalParams,
241
+ ...formData,
242
+ }
243
+ }
244
+ })
245
+ }
246
+
247
+ await uni.$lcb.http.post(props.requestInfo.requestUrl, finalParams)
248
+ }
232
249
  /** 请求之后刷新schemaPage */
233
250
  if ('requestInfo' in props && props.requestInfo?.refreshSchemaPage) {
234
251
  uni.$emit('refreshSchemaPage')
@@ -23,6 +23,8 @@ export type LcbActionViewProps = {
23
23
  requestParams: Record<string, any>
24
24
  /** 请求之后刷新schemapage */
25
25
  refreshSchemaPage?: boolean
26
+ /** 绑定的表单 keys,请求时会将对应表单数据合并到 requestParams */
27
+ formKeys?: string[]
26
28
  }
27
29
  submitRequestInfo?: {
28
30
  requestUrl: string
@@ -128,12 +128,25 @@ const innerValue = computed(() => {
128
128
  })
129
129
 
130
130
  const actionProps = computed(() => {
131
- return resolveActionProps({
131
+ const resolvedProps = resolveActionProps({
132
132
  dynamicActionKey: props.dynamicActionKey,
133
133
  action: props.action as any,
134
134
  innerDynamicData: innerDynamicData.value,
135
135
  templateStore: store.value,
136
136
  })
137
+
138
+ // 如果 button 有 formKeys,传递给 action 的 requestInfo
139
+ if (props.formKeys && resolvedProps.requestInfo) {
140
+ return {
141
+ ...resolvedProps,
142
+ requestInfo: {
143
+ ...resolvedProps.requestInfo,
144
+ formKeys: props.formKeys,
145
+ },
146
+ }
147
+ }
148
+
149
+ return resolvedProps
137
150
  })
138
151
 
139
152
  const onAvatar = (headImgUrl) => {
@@ -40,4 +40,6 @@ export interface LcbButtonProps extends LcbBlockProps {
40
40
  lineClamp?: number
41
41
  progressProps?: ExtractPropTypes<typeof progressProps>
42
42
  fontFamily?: string
43
+ // 绑定的表单 keys,请求时会将对应表单数据一并提交
44
+ formKeys?: string[]
43
45
  }
@@ -6,7 +6,6 @@
6
6
  <wd-cell
7
7
  v-for="field in fields"
8
8
  :key="field.entryFormFieldConfigId"
9
- :title="field.fieldCustomName"
10
9
  :required="field.requiredFlag"
11
10
  :prop="field.field"
12
11
  :title-width="!vertical ? '230rpx' : '100%'"
@@ -22,6 +21,11 @@
22
21
  : []
23
22
  "
24
23
  >
24
+ <template #title>
25
+ <view :style="titleStyle">
26
+ {{ field.fieldCustomName }}
27
+ </view>
28
+ </template>
25
29
  <wd-input
26
30
  v-if="field.frontInputType === 'input'"
27
31
  :placeholder="field.frontPlaceholder || t('请输入') + field.fieldCustomName"
@@ -155,7 +159,7 @@
155
159
  </wd-cell-group>
156
160
  <view
157
161
  :class="{ 'bottom-fixed': bottomFixed, 'mt-3': !bottomFixed }"
158
- v-if="submitText || agreementType"
162
+ v-if="(showSubmitButton && submitText) || agreementType"
159
163
  >
160
164
  <view class="text-center text-3 mt-3" v-if="agreementType && fields">
161
165
  <wd-checkbox v-model="form.agreement">
@@ -177,7 +181,7 @@
177
181
  block
178
182
  size="large"
179
183
  custom-class="!w-90% mt-3 !mx-auto"
180
- v-if="fields && submitText"
184
+ v-if="fields && submitText && showSubmitButton"
181
185
  >
182
186
  {{ t(submitText) }}
183
187
  </wd-button>
@@ -188,12 +192,14 @@
188
192
  </template>
189
193
 
190
194
  <script setup lang="ts">
191
- import { ref, watch } from 'vue'
195
+ import { ref, watch, computed, inject, Ref } from 'vue'
192
196
  import { LcbFormField, LcbFormProps } from './types'
193
197
  import { customUpload } from '../../utils/utils'
194
198
  import { useTranslate } from '@tplc/wot'
195
199
  import { DateTimeType } from '@tplc/wot/types/components/wd-datetime-picker-view/types'
196
200
  import dayjs from 'dayjs/esm'
201
+ import { transformValueUnit } from '../../utils/transform'
202
+ import { PAGE_PROVIDE_KEY } from '../../constants'
197
203
  defineOptions({
198
204
  name: 'LcbForm',
199
205
  options: {
@@ -214,8 +220,29 @@ const props = withDefaults(defineProps<LcbFormProps>(), {
214
220
  submitText: '提交',
215
221
  affirmText: '同意',
216
222
  bottomFixed: true,
223
+ showSubmitButton: true,
217
224
  vertical: false,
225
+ titleFontSize: 28,
226
+ titleFontWeight: 'normal',
227
+ })
228
+
229
+ // 注入页面上下文
230
+ const pageInfo = inject(PAGE_PROVIDE_KEY) as Ref<Record<string, any>>
231
+
232
+ // 计算 title 样式
233
+ const titleStyle = computed(() => {
234
+ return {
235
+ color: props.titleColor,
236
+ fontSize: transformValueUnit(props.titleFontSize),
237
+ fontWeight: props.titleFontWeight,
238
+ fontFamily: props.titleFontFamily,
239
+ }
218
240
  })
241
+
242
+ defineSlots<{
243
+ title(props: { field: LcbFormField }): any
244
+ }>()
245
+
219
246
  const fields = ref<LcbFormField[]>(props.fields)
220
247
  const customInputs = ref<Record<string, string>>({})
221
248
  const customField = 'custom'
@@ -356,8 +383,12 @@ watch(
356
383
  form,
357
384
  (newVal) => {
358
385
  formData.value = newVal
386
+ // 如果设置了 formKey,将表单数据同步到 PAGE_PROVIDE_KEY
387
+ if (props.formKey && pageInfo.value) {
388
+ pageInfo.value[props.formKey] = newVal
389
+ }
359
390
  },
360
- { deep: true },
391
+ { deep: true, immediate: true },
361
392
  )
362
393
  </script>
363
394
 
@@ -80,5 +80,14 @@ export interface LcbFormProps extends LcbBlockProps {
80
80
  affirmText?: string
81
81
  // 底部悬浮
82
82
  bottomFixed?: boolean
83
+ // 是否显示提交按钮
84
+ showSubmitButton?: boolean
83
85
  vertical?: boolean
86
+ // 标题样式配置
87
+ titleColor?: string
88
+ titleFontSize?: number
89
+ titleFontWeight?: string | number
90
+ titleFontFamily?: string
91
+ // 表单唯一标识,用于在 PAGE_PROVIDE_KEY 中注册表单数据
92
+ formKey?: string
84
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tplc/business",
3
- "version": "0.7.75",
3
+ "version": "0.7.76",
4
4
  "keywords": [
5
5
  "业务组件"
6
6
  ],
@@ -21,6 +21,8 @@ export type LcbActionViewProps = {
21
21
  requestParams: Record<string, any>
22
22
  /** 请求之后刷新schemapage */
23
23
  refreshSchemaPage?: boolean
24
+ /** 绑定的表单 keys,请求时会将对应表单数据合并到 requestParams */
25
+ formKeys?: string[]
24
26
  }
25
27
  submitRequestInfo?: {
26
28
  requestUrl: string
@@ -36,4 +36,5 @@ export interface LcbButtonProps extends LcbBlockProps {
36
36
  lineClamp?: number
37
37
  progressProps?: ExtractPropTypes<typeof progressProps>
38
38
  fontFamily?: string
39
+ formKeys?: string[]
39
40
  }
@@ -1,16 +1,24 @@
1
- import { LcbFormProps } from './types'
1
+ import { LcbFormField, LcbFormProps } from './types'
2
2
  declare let __VLS_typeProps: LcbFormProps
3
3
  type __VLS_PublicProps = {
4
4
  modelValue?: Record<string, any>
5
5
  } & typeof __VLS_typeProps
6
- declare const _default: import('vue').DefineComponent<
6
+ declare function __VLS_template(): Readonly<{
7
+ title(props: { field: LcbFormField }): any
8
+ }> & {
9
+ title(props: { field: LcbFormField }): any
10
+ }
11
+ declare const __VLS_component: import('vue').DefineComponent<
7
12
  __VLS_WithDefaults<
8
13
  __VLS_TypePropsToOption<__VLS_PublicProps>,
9
14
  {
10
15
  submitText: string
11
16
  affirmText: string
12
17
  bottomFixed: boolean
18
+ showSubmitButton: boolean
13
19
  vertical: boolean
20
+ titleFontSize: number
21
+ titleFontWeight: string
14
22
  }
15
23
  >,
16
24
  {},
@@ -32,7 +40,10 @@ declare const _default: import('vue').DefineComponent<
32
40
  submitText: string
33
41
  affirmText: string
34
42
  bottomFixed: boolean
43
+ showSubmitButton: boolean
35
44
  vertical: boolean
45
+ titleFontSize: number
46
+ titleFontWeight: string
36
47
  }
37
48
  >
38
49
  >
@@ -41,12 +52,19 @@ declare const _default: import('vue').DefineComponent<
41
52
  },
42
53
  {
43
54
  vertical: boolean
55
+ titleFontSize: number
56
+ titleFontWeight: string | number
44
57
  submitText: string
45
58
  affirmText: string
46
59
  bottomFixed: boolean
60
+ showSubmitButton: boolean
47
61
  },
48
62
  {}
49
63
  >
64
+ declare const _default: __VLS_WithTemplateSlots<
65
+ typeof __VLS_component,
66
+ ReturnType<typeof __VLS_template>
67
+ >
50
68
  export default _default
51
69
  type __VLS_WithDefaults<P, D> = {
52
70
  [K in keyof Pick<P, keyof P>]: K extends keyof D
@@ -60,6 +78,11 @@ type __VLS_WithDefaults<P, D> = {
60
78
  type __VLS_Prettify<T> = {
61
79
  [K in keyof T]: T[K]
62
80
  } & {}
81
+ type __VLS_WithTemplateSlots<T, S> = T & {
82
+ new (): {
83
+ $slots: S
84
+ }
85
+ }
63
86
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T
64
87
  type __VLS_TypePropsToOption<T> = {
65
88
  [K in keyof T]-?: {} extends Pick<T, K>
@@ -78,5 +78,11 @@ export interface LcbFormProps extends LcbBlockProps {
78
78
  agreementType?: string
79
79
  affirmText?: string
80
80
  bottomFixed?: boolean
81
+ showSubmitButton?: boolean
81
82
  vertical?: boolean
83
+ titleColor?: string
84
+ titleFontSize?: number
85
+ titleFontWeight?: string | number
86
+ titleFontFamily?: string
87
+ formKey?: string
82
88
  }
@@ -85,6 +85,7 @@ declare const _default: import('vue').DefineComponent<
85
85
  requestUrl: string
86
86
  requestParams: Record<string, any>
87
87
  refreshSchemaPage?: boolean
88
+ formKeys?: string[]
88
89
  }
89
90
  submitRequestInfo?: {
90
91
  requestUrl: string
@@ -194,6 +195,7 @@ declare const _default: import('vue').DefineComponent<
194
195
  requestUrl: string
195
196
  requestParams: Record<string, any>
196
197
  refreshSchemaPage?: boolean
198
+ formKeys?: string[]
197
199
  }
198
200
  submitRequestInfo?: {
199
201
  requestUrl: string
@@ -280,6 +282,7 @@ declare const _default: import('vue').DefineComponent<
280
282
  requestUrl: string
281
283
  requestParams: Record<string, any>
282
284
  refreshSchemaPage?: boolean
285
+ formKeys?: string[]
283
286
  }
284
287
  submitRequestInfo?: {
285
288
  requestUrl: string
@@ -366,6 +369,7 @@ declare const _default: import('vue').DefineComponent<
366
369
  requestUrl: string
367
370
  requestParams: Record<string, any>
368
371
  refreshSchemaPage?: boolean
372
+ formKeys?: string[]
369
373
  }
370
374
  submitRequestInfo?: {
371
375
  requestUrl: string
@@ -451,6 +455,7 @@ declare const _default: import('vue').DefineComponent<
451
455
  requestUrl: string
452
456
  requestParams: Record<string, any>
453
457
  refreshSchemaPage?: boolean
458
+ formKeys?: string[]
454
459
  }
455
460
  submitRequestInfo?: {
456
461
  requestUrl: string
@@ -542,6 +547,7 @@ declare const _default: import('vue').DefineComponent<
542
547
  requestUrl: string
543
548
  requestParams: Record<string, any>
544
549
  refreshSchemaPage?: boolean
550
+ formKeys?: string[]
545
551
  }
546
552
  submitRequestInfo?: {
547
553
  requestUrl: string
@@ -627,6 +633,7 @@ declare const _default: import('vue').DefineComponent<
627
633
  requestUrl: string
628
634
  requestParams: Record<string, any>
629
635
  refreshSchemaPage?: boolean
636
+ formKeys?: string[]
630
637
  }
631
638
  submitRequestInfo?: {
632
639
  requestUrl: string
@@ -712,6 +719,7 @@ declare const _default: import('vue').DefineComponent<
712
719
  requestUrl: string
713
720
  requestParams: Record<string, any>
714
721
  refreshSchemaPage?: boolean
722
+ formKeys?: string[]
715
723
  }
716
724
  submitRequestInfo?: {
717
725
  requestUrl: string
@@ -801,6 +809,7 @@ declare const _default: import('vue').DefineComponent<
801
809
  requestUrl: string
802
810
  requestParams: Record<string, any>
803
811
  refreshSchemaPage?: boolean
812
+ formKeys?: string[]
804
813
  }
805
814
  submitRequestInfo?: {
806
815
  requestUrl: string
@@ -887,6 +896,7 @@ declare const _default: import('vue').DefineComponent<
887
896
  requestUrl: string
888
897
  requestParams: Record<string, any>
889
898
  refreshSchemaPage?: boolean
899
+ formKeys?: string[]
890
900
  }
891
901
  submitRequestInfo?: {
892
902
  requestUrl: string