1
1
<script setup lang="ts">
2
2
import { toTypedSchema } from ' @vee-validate/yup'
3
- import { Info } from ' lucide-vue-next'
4
3
import { Field , Form } from ' vee-validate'
5
4
import * as yup from ' yup'
6
5
import { addPrefix } from ' @/utils'
@@ -15,6 +14,17 @@ interface Config {
15
14
name: string
16
15
logo: string
17
16
desc: string
17
+ /**
18
+ * 1: 公众号
19
+ * 2: 服务号
20
+ */
21
+ serviceType: ` 1 ` | ` 2 `
22
+ /**
23
+ * 0: 无标识
24
+ * 1: 个人认证
25
+ * 2: 企业认证
26
+ */
27
+ verify: ` 0 ` | ` 1 ` | ` 2 `
18
28
}
19
29
20
30
/** 表单字段 */
@@ -23,42 +33,17 @@ const config = useStorage<Config>(addPrefix(`mp-profile`), {
23
33
name: ` ` ,
24
34
logo: ` ` ,
25
35
desc: ` ` ,
26
- })
27
-
28
- /**
29
- * @deprecated 更换为对象形式,后续版本可移除该兼容写法
30
- */
31
- const mpId = useStorage (` mpId ` , ` ` )
32
- /**
33
- * @deprecated 更换为对象形式,后续版本可移除该兼容写法
34
- */
35
- const mpName = useStorage (` mpName ` , ` ` )
36
- /**
37
- * @deprecated 更换为对象形式,后续版本可移除该兼容写法
38
- */
39
- const mpLogo = useStorage (` mpLogo ` , ` ` )
40
- /**
41
- * @deprecated 更换为对象形式,后续版本可移除该兼容写法
42
- */
43
- const mpDesc = useStorage (` mpDesc ` , ` ` )
44
-
45
- onMounted (() => {
46
- config .value .id = mpId .value || config .value .id
47
- config .value .name = mpName .value || config .value .name
48
- config .value .logo = mpLogo .value || config .value .logo
49
- config .value .desc = mpDesc .value || config .value .desc
50
-
51
- mpId .value = ` `
52
- mpName .value = ` `
53
- mpLogo .value = ` `
54
- mpDesc .value = ` `
36
+ serviceType: ` 1 ` ,
37
+ verify: ` 0 ` ,
55
38
})
56
39
57
40
const schema = toTypedSchema (yup .object ({
58
41
id: yup .string ().required (` 公众号 ID 不能为空 ` ),
59
42
name: yup .string ().required (` 公众号名称 不能为空 ` ),
60
43
logo: yup .string ().optional ().url (` 公众号 Logo 必须是一个有效的 URL ` ),
61
44
desc: yup .string ().optional (),
45
+ serviceType: yup .string ().required (),
46
+ verify: yup .string ().required (),
62
47
}))
63
48
64
49
/** 组装 HTML 片段 */
@@ -70,8 +55,8 @@ function buildMpHtml(config: Config) {
70
55
` data-nickname="${config .name }" ` ,
71
56
` data-headimg="${logo }" ` ,
72
57
config .desc && ` data-signature="${config .desc }" ` ,
73
- ` data-service_type="1 " ` ,
74
- ` data-verify_status="1 " ` ,
58
+ ` data-service_type="${ config . serviceType || ` 1 ` } " ` ,
59
+ ` data-verify_status="${ config . verify || ` 0 ` } " ` ,
75
60
].filter (Boolean ).join (` ` )
76
61
77
62
return ` <section class="mp_profile_iframe_wrp custom_select_card_wrp" nodeleaf="">
@@ -96,17 +81,9 @@ function submit(formValues: any) {
96
81
<DialogTitle >插入公众号名片</DialogTitle >
97
82
</DialogHeader >
98
83
99
- <Alert >
100
- <Info class =" h-4 w-4" />
101
- <AlertTitle >提示</AlertTitle >
102
- <AlertDescription >
103
- 此功能用于插入微信公众号名片,数据会缓存至本地,可长期使用。
104
- </AlertDescription >
105
- </Alert >
106
-
107
84
<Form :validation-schema =" schema" :initial-values =" config" @submit =" submit" >
108
85
<Field v-slot =" { field, errorMessage }" name =" id" >
109
- <FormItem label =" 公众号 ID" required :error =" errorMessage" >
86
+ <FormItem label =" 公众号 ID" required :error =" errorMessage" :width = " 90 " >
110
87
<Input
111
88
v-bind =" field"
112
89
v-model.trim =" field.value"
@@ -116,7 +93,7 @@ function submit(formValues: any) {
116
93
</Field >
117
94
118
95
<Field v-slot =" { field, errorMessage }" name =" name" >
119
- <FormItem label =" 公众号名称" required :error =" errorMessage" >
96
+ <FormItem label =" 公众号名称" required :error =" errorMessage" :width = " 90 " >
120
97
<Input
121
98
v-bind =" field"
122
99
v-model.trim =" field.value"
@@ -126,7 +103,7 @@ function submit(formValues: any) {
126
103
</Field >
127
104
128
105
<Field v-slot =" { field, errorMessage }" name =" logo" >
129
- <FormItem label =" 公众号 Logo" :error =" errorMessage" >
106
+ <FormItem label =" 公众号 Logo" :error =" errorMessage" :width = " 90 " >
130
107
<Input
131
108
v-bind =" field"
132
109
v-model.trim =" field.value"
@@ -136,7 +113,7 @@ function submit(formValues: any) {
136
113
</Field >
137
114
138
115
<Field v-slot =" { field, errorMessage }" name =" desc" >
139
- <FormItem label =" 公众号描述" :error =" errorMessage" >
116
+ <FormItem label =" 公众号描述" :error =" errorMessage" :width = " 90 " >
140
117
<Textarea
141
118
v-bind =" field"
142
119
v-model.trim =" field.value"
@@ -146,6 +123,52 @@ function submit(formValues: any) {
146
123
</FormItem >
147
124
</Field >
148
125
126
+ <Field v-slot =" { field, errorMessage }" name =" serviceType" >
127
+ <FormItem label =" 公众号类型" required :error =" errorMessage" :width =" 90" >
128
+ <RadioGroup class =" flex gap-5" v-bind =" field" :default-value =" field.value" >
129
+ <div class =" inline-flex items-center space-x-2 w-20" >
130
+ <RadioGroupItem id =" option-one" value =" 1" />
131
+ <Label for =" option-one" >公众号</Label >
132
+ </div >
133
+ <div class =" inline-flex items-center space-x-2 w-20" >
134
+ <RadioGroupItem id =" option-two" value =" 2" />
135
+ <Label for =" option-two" >服务号</Label >
136
+ </div >
137
+ </RadioGroup >
138
+ </FormItem >
139
+ </Field >
140
+
141
+ <Field v-slot =" { field, errorMessage }" name =" verify" >
142
+ <FormItem label =" 认证" required :error =" errorMessage" :width =" 90" >
143
+ <RadioGroup class =" flex gap-5" v-bind =" field" :default-value =" field.value" >
144
+ <div class =" inline-flex items-center space-x-2 w-20" >
145
+ <RadioGroupItem id =" service-type-option-one" value =" 0" />
146
+ <Label for =" service-type-option-one" >无</Label >
147
+ </div >
148
+ <div class =" inline-flex items-center space-x-2 w-20" >
149
+ <RadioGroupItem id =" service-type-option-two" value =" 1" />
150
+ <Label for =" service-type-option-two" >个人</Label >
151
+ </div >
152
+ <div class =" inline-flex items-center space-x-2 w-20" >
153
+ <RadioGroupItem id =" service-type-option-three" value =" 2" />
154
+ <Label for =" service-type-option-three" >企业</Label >
155
+ </div >
156
+ </RadioGroup >
157
+ </FormItem >
158
+ </Field >
159
+
160
+ <FormItem >
161
+ <Button
162
+ variant =" link"
163
+ class =" p-0 h-auto text-left whitespace-normal"
164
+ as =" a"
165
+ href =" https://github.com/doocs/md/blob/main/docs/mp-card.md"
166
+ target =" _blank"
167
+ >
168
+ 如何获取公众号 ID?
169
+ </Button >
170
+ </FormItem >
171
+
149
172
<FormItem >
150
173
<Button type =" submit" >
151
174
确认
0 commit comments