feat: 支持动态咨询字段类型
This commit is contained in:
1 parent
3186757d93
commit
6d2c12c3df
4 files changed
+28
-3
No files matched your search
+18
-1
@@ -282,7 +282,24 @@ export class PublicWorkspaceController {
|
||||
].includes(String(value.type))
|
||||
? (value.type as RuntimeInquiryField["type"])
|
||||
: "text";
|
||||
return [{ key: value.key, label: value.label, type, required: value.required === true }];
|
||||
const options = Array.isArray(value.options)
|
||||
? value.options.flatMap((option) => {
|
||||
if (!option || typeof option !== "object") return [];
|
||||
const item = option as Record<string, unknown>;
|
||||
return typeof item.label === "string" && typeof item.value === "string"
|
||||
? [{ label: item.label, value: item.value }]
|
||||
: [];
|
||||
})
|
||||
: undefined;
|
||||
return [
|
||||
{
|
||||
key: value.key,
|
||||
label: value.label,
|
||||
type,
|
||||
required: value.required === true,
|
||||
...(options?.length ? { options } : {}),
|
||||
},
|
||||
];
|
||||
});
|
||||
const inquiryForm = inquiryForms[0] ?? null;
|
||||
const runtimeWorkspace: RuntimeWorkspace = {
|
||||
|
||||
@@ -9,6 +9,14 @@ Component({
|
||||
input(e) {
|
||||
this.triggerEvent("input", { key: e.currentTarget.dataset.key, value: e.detail.value });
|
||||
},
|
||||
choose(e) {
|
||||
const field = this.data.fields.find((item) => item.key === e.currentTarget.dataset.key);
|
||||
const option = field?.options?.[e.detail.value];
|
||||
if (option) this.triggerEvent("input", { key: field.key, value: option.value });
|
||||
},
|
||||
dateChange(e) {
|
||||
this.triggerEvent("input", { key: e.currentTarget.dataset.key, value: e.detail.value });
|
||||
},
|
||||
submit() {
|
||||
this.triggerEvent("submit");
|
||||
},
|
||||
|
||||
@@ -1 +1 @@
|
||||
<view class="form"><view wx:for="{{fields}}" wx:key="key" class="field"><text>{{item.label}}</text><input data-key="{{item.key}}" placeholder="{{item.placeholder}}" value="{{values[item.key]}}" bindinput="input"/></view><button class="submit" loading="{{submitting}}" bindtap="submit">{{submitLabel || '提交需求'}}</button><text class="privacy">信息仅用于本次方案沟通,我们不会向第三方披露。</text></view>
|
||||
<view class="form"><view wx:for="{{fields}}" wx:key="key" class="field"><text class="label">{{item.label}}{{item.required ? ' *' : ''}}</text><input wx:if="{{item.type === 'tel' || item.type === 'phone' || item.type === 'number' || item.type === 'text'}}" type="{{item.type === 'number' ? 'number' : item.type === 'tel' || item.type === 'phone' ? 'number' : 'text'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input"/><textarea wx:elif="{{item.type === 'textarea'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input" auto-height="true"/><picker wx:elif="{{item.type === 'date'}}" mode="date" data-key="{{item.key}}" value="{{values[item.key]}}" bindchange="dateChange"><view class="picker-value">{{values[item.key] || '请选择日期'}}</view></picker><picker wx:elif="{{item.type === 'select' || item.type === 'radio'}}" mode="selector" range="{{item.options}}" range-key="label" data-key="{{item.key}}" bindchange="choose"><view class="picker-value">{{values[item.key] || '请选择'}}</view></picker></view><button class="submit" loading="{{submitting}}" bindtap="submit">{{submitLabel || '提交需求'}}</button><text class="privacy">信息仅用于本次方案沟通,我们不会向第三方披露。</text></view>
|
||||
@@ -1 +1 @@
|
||||
.form{margin-top:24rpx;padding:30rpx;background:#fff}.field{display:flex;align-items:center;gap:20rpx;padding:24rpx 0;border-bottom:1rpx solid #e6ded5}.field text{width:180rpx;color:#77736b;font-size:26rpx}.field input{flex:1;font-size:26rpx}.submit{margin-top:30rpx;background:#252827;color:#fff;border-radius:0}.privacy{display:block;margin-top:20rpx;color:#99928a;font-size:21rpx;text-align:center}
|
||||
.form{margin-top:24rpx;padding:30rpx;background:#fff}.field{display:flex;align-items:flex-start;gap:20rpx;padding:24rpx 0;border-bottom:1rpx solid #e6ded5}.label{width:180rpx;flex:none;color:#77736b;font-size:26rpx}.field input,.field textarea,.picker-value{flex:1;font-size:26rpx;color:#252827}.field textarea{min-height:80rpx}.picker-value{color:#77736b}.submit{margin-top:30rpx;background:#252827;color:#fff;border-radius:0}.privacy{display:block;margin-top:20rpx;color:#99928a;font-size:21rpx;text-align:center}
|
||||
Reference in new issue
Block a user