hookehuyr

新数据结构入口改造

1 /* 1 /*
2 * @Date: 2022-06-17 14:54:29 2 * @Date: 2022-06-17 14:54:29
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-12-06 11:22:36 4 + * @LastEditTime: 2022-12-16 15:57:01
5 * @FilePath: /data-table/src/api/form.js 5 * @FilePath: /data-table/src/api/form.js
6 * @Description: 表单接口 6 * @Description: 表单接口
7 */ 7 */
...@@ -9,7 +9,7 @@ import { fn, fetch } from '@/api/fn'; ...@@ -9,7 +9,7 @@ import { fn, fetch } from '@/api/fn';
9 9
10 const Api = { 10 const Api = {
11 FORM_ADD: '/srv/?a=add_form', 11 FORM_ADD: '/srv/?a=add_form',
12 - FORM_QUERY: '/srv/?a=query_form', 12 + FORM_QUERY: '/srv/?a=query_form_all_field',
13 ADD_FORM_FIELD: '/srv/?a=add_form_field', 13 ADD_FORM_FIELD: '/srv/?a=add_form_field',
14 ADD_FORM_SETTING: '/srv/?a=add_form_setting', 14 ADD_FORM_SETTING: '/srv/?a=add_form_setting',
15 QUERY_FORM_SETTING: '/srv/?a=query_form_setting', 15 QUERY_FORM_SETTING: '/srv/?a=query_form_setting',
......
...@@ -30,7 +30,7 @@ import ButtonField from '@/components/ButtonField/index.vue' ...@@ -30,7 +30,7 @@ import ButtonField from '@/components/ButtonField/index.vue'
30 /** 30 /**
31 * 生成自定义组件类型 31 * 生成自定义组件类型
32 * @param {*} data 32 * @param {*} data
33 - * @type text 单行文本 TextField 33 + * @type input 单行文本 TextField
34 * @type textarea 多行文本 TextareaField 34 * @type textarea 多行文本 TextareaField
35 * @type radio 单项选择 RadioField 35 * @type radio 单项选择 RadioField
36 * @type checkbox 多项选择 CheckboxField 36 * @type checkbox 多项选择 CheckboxField
...@@ -60,102 +60,102 @@ export function createComponentType(data) { ...@@ -60,102 +60,102 @@ export function createComponentType(data) {
60 if (item.component_props.required) { 60 if (item.component_props.required) {
61 item.rules = [{ required: true, message: item.placeholder ? item.placeholder : '必填项不能为空' }] 61 item.rules = [{ required: true, message: item.placeholder ? item.placeholder : '必填项不能为空' }]
62 } 62 }
63 - if (item.component_props.name === 'text') { 63 + if (item.component_props.tag === 'input') {
64 item.type = 'text'; 64 item.type = 'text';
65 item.name = item.key; 65 item.name = item.key;
66 item.component = TextField; 66 item.component = TextField;
67 } 67 }
68 - if (item.component_props.name === 'textarea') { 68 + if (item.component_props.tag === 'textarea') {
69 item.type = 'textarea'; 69 item.type = 'textarea';
70 item.name = item.key; 70 item.name = item.key;
71 // item.rows = 10; 71 // item.rows = 10;
72 item.autosize = true; 72 item.autosize = true;
73 item.component = TextareaField; 73 item.component = TextareaField;
74 } 74 }
75 - if (item.component_props.name === 'number') { 75 + if (item.component_props.tag === 'number') {
76 item.name = item.key; 76 item.name = item.key;
77 item.component = NumberField; 77 item.component = NumberField;
78 } 78 }
79 - if (item.component_props.name === 'radio') { 79 + if (item.component_props.tag === 'radio') {
80 item.component = RadioField; 80 item.component = RadioField;
81 } 81 }
82 - if (item.component_props.name === 'checkbox') { 82 + if (item.component_props.tag === 'checkbox') {
83 item.component = CheckboxField; 83 item.component = CheckboxField;
84 } 84 }
85 - if (item.component_props.name === 'picker') { 85 + if (item.component_props.tag === 'picker') {
86 item.component = PickerField; 86 item.component = PickerField;
87 } 87 }
88 - if (item.component_props.name === 'area_picker') { 88 + if (item.component_props.tag === 'area_picker') {
89 item.component = AreaPickerField; 89 item.component = AreaPickerField;
90 } 90 }
91 - if (item.component_props.name === 'date_picker') { 91 + if (item.component_props.tag === 'date_picker') {
92 item.component = DatePickerField; 92 item.component = DatePickerField;
93 } 93 }
94 - if (item.component_props.name === 'time_picker') { 94 + if (item.component_props.tag === 'time_picker') {
95 item.component = TimePickerField; 95 item.component = TimePickerField;
96 } 96 }
97 - if (item.component_props.name === 'datetime_picker') { 97 + if (item.component_props.tag === 'datetime_picker') {
98 item.component = DateTimePickerField; 98 item.component = DateTimePickerField;
99 } 99 }
100 - if (item.component_props.name === 'image_uploader') { 100 + if (item.component_props.tag === 'image_uploader') {
101 item.component = ImageUploaderField; 101 item.component = ImageUploaderField;
102 } 102 }
103 - if (item.component_props.name === 'file_uploader') { 103 + if (item.component_props.tag === 'file_uploader') {
104 item.component = FileUploaderField; 104 item.component = FileUploaderField;
105 } 105 }
106 - if (item.component_props.name === 'phone') { 106 + if (item.component_props.tag === 'phone') {
107 item.name = item.key; 107 item.name = item.key;
108 item.component = PhoneField; 108 item.component = PhoneField;
109 } 109 }
110 - if (item.component_props.name === 'email') { 110 + if (item.component_props.tag === 'email') {
111 item.name = item.key; 111 item.name = item.key;
112 item.component = EmailField; 112 item.component = EmailField;
113 } 113 }
114 - if (item.component_props.name === 'sign') { 114 + if (item.component_props.tag === 'sign') {
115 item.name = item.key; 115 item.name = item.key;
116 item.component = SignField; 116 item.component = SignField;
117 } 117 }
118 - if (item.component_props.name === 'rate_picker') { 118 + if (item.component_props.tag === 'rate_picker') {
119 item.name = item.key; 119 item.name = item.key;
120 item.component = RatePickerField; 120 item.component = RatePickerField;
121 } 121 }
122 - if (item.component_props.name === 'calendar') { 122 + if (item.component_props.tag === 'calendar') {
123 item.name = item.key; 123 item.name = item.key;
124 item.component = CalendarField; 124 item.component = CalendarField;
125 } 125 }
126 - if (item.component_props.name === 'id_code') { 126 + if (item.component_props.tag === 'id_code') {
127 item.name = item.key; 127 item.name = item.key;
128 item.component = IdentityField; 128 item.component = IdentityField;
129 } 129 }
130 - if (item.component_props.name === 'desc') { 130 + if (item.component_props.tag === 'desc') {
131 item.name = item.key; 131 item.name = item.key;
132 item.component = DesField; 132 item.component = DesField;
133 } 133 }
134 - if (item.component_props.name === 'divider') { 134 + if (item.component_props.tag === 'divider') {
135 item.name = item.key; 135 item.name = item.key;
136 item.component = DividerField; 136 item.component = DividerField;
137 } 137 }
138 - if (item.component_props.name === 'video') { 138 + if (item.component_props.tag === 'video') {
139 item.name = item.key; 139 item.name = item.key;
140 item.component = VideoField; 140 item.component = VideoField;
141 } 141 }
142 - if (item.component_props.name === 'marquee') { 142 + if (item.component_props.tag === 'marquee') {
143 item.name = item.key; 143 item.name = item.key;
144 item.component = MarqueeField; 144 item.component = MarqueeField;
145 } 145 }
146 - if (item.component_props.name === 'contact') { 146 + if (item.component_props.tag === 'contact') {
147 item.name = item.key; 147 item.name = item.key;
148 item.component = ContactField; 148 item.component = ContactField;
149 } 149 }
150 - if (item.component_props.name === 'rule') { 150 + if (item.component_props.tag === 'rule') {
151 item.name = item.key; 151 item.name = item.key;
152 item.component = RuleField; 152 item.component = RuleField;
153 } 153 }
154 - if (item.component_props.name === 'button') { 154 + if (item.component_props.tag === 'button') {
155 item.name = item.key; 155 item.name = item.key;
156 item.component = ButtonField; 156 item.component = ButtonField;
157 } 157 }
158 - if (item.component_props.name === 'multi_rule') { 158 + if (item.component_props.tag === 'multi_rule') {
159 item.name = item.key; 159 item.name = item.key;
160 item.value = []; 160 item.value = [];
161 item.component = MultiRuleField; 161 item.component = MultiRuleField;
......
1 <!-- 1 <!--
2 * @Date: 2022-07-18 10:22:22 2 * @Date: 2022-07-18 10:22:22
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-12-09 15:25:00 4 + * @LastEditTime: 2022-12-16 16:38:31
5 * @FilePath: /data-table/src/views/index.vue 5 * @FilePath: /data-table/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -122,40 +122,11 @@ const model = $route.query.model; ...@@ -122,40 +122,11 @@ const model = $route.query.model;
122 const formatData = (data) => { 122 const formatData = (data) => {
123 const arr = []; 123 const arr = [];
124 data.forEach((field) => { 124 data.forEach((field) => {
125 + const { interaction_type, data_type, field_id, field_name, ...component_props } = field;
125 // 生成组件属性 126 // 生成组件属性
126 - const component_props = {
127 - name: field.component_code,
128 - };
129 - if (field.component_type === "h5edit") {
130 - // 编辑组件
131 - field.property_list.forEach((prop) => {
132 - const key = prop["property_code"];
133 - const obj = {
134 - [key]:
135 - prop["setting_value"].length > 1
136 - ? prop["setting_value"]
137 - : prop["setting_value"][0],
138 - };
139 - Object.assign(component_props, obj);
140 - });
141 - } else {
142 - // 展示组件
143 - field.property_list.forEach((prop) => {
144 - const key = prop["property_code"];
145 - const obj = {
146 - [key]:
147 - key !== 'label'
148 - ? prop["setting_value"]
149 - : prop["setting_value"][0],
150 - };
151 - Object.assign(component_props, obj);
152 - });
153 - }
154 - // 绑定组件名称标识
155 const temp = { 127 const temp = {
156 - key: field.field_name, 128 + key: field_name,
157 value: component_props.default ? component_props.default : "", 129 value: component_props.default ? component_props.default : "",
158 - component: field.component_code,
159 component_props, 130 component_props,
160 }; 131 };
161 arr.push(temp); 132 arr.push(temp);
...@@ -173,19 +144,19 @@ const rate_picker = ref([]); ...@@ -173,19 +144,19 @@ const rate_picker = ref([]);
173 // 动态绑定ref数据 144 // 动态绑定ref数据
174 const setRefMap = (el, item) => { 145 const setRefMap = (el, item) => {
175 if (el) { 146 if (el) {
176 - if (item.component_props.name === "area_picker") { 147 + if (item.component_props.tag === "area_picker") {
177 area_picker.value.push(el); 148 area_picker.value.push(el);
178 } 149 }
179 - if (item.component_props.name === "image_uploader") { 150 + if (item.component_props.tag === "image_uploader") {
180 image_uploader.value.push(el); 151 image_uploader.value.push(el);
181 } 152 }
182 - if (item.component_props.name === "file_uploader") { 153 + if (item.component_props.tag === "file_uploader") {
183 file_uploader.value.push(el); 154 file_uploader.value.push(el);
184 } 155 }
185 - if (item.component_props.name === "sign") { 156 + if (item.component_props.tag === "sign") {
186 sign.value.push(el); 157 sign.value.push(el);
187 } 158 }
188 - if (item.component_props.name === "rate_picker") { 159 + if (item.component_props.tag === "rate_picker") {
189 rate_picker.value.push(el); 160 rate_picker.value.push(el);
190 } 161 }
191 } 162 }
...@@ -201,27 +172,20 @@ onMounted(async () => { ...@@ -201,27 +172,20 @@ onMounted(async () => {
201 .querySelector("body") 172 .querySelector("body")
202 .setAttribute("style", `background-color: ${styleColor.backgroundColor}`); 173 .setAttribute("style", `background-color: ${styleColor.backgroundColor}`);
203 const { data } = await queryFormAPI({ form_code: $route.query.code }); 174 const { data } = await queryFormAPI({ form_code: $route.query.code });
204 - const form_data = data[0]; 175 + const form_data = data;
176 + // 表单网页标题
205 useTitle(form_data.name); 177 useTitle(form_data.name);
206 // 重构数据结构 178 // 重构数据结构
207 let page_header = {}; 179 let page_header = {};
208 let page_commit = {}; 180 let page_commit = {};
209 let page_form = []; 181 let page_form = [];
210 form_data.field_list.forEach((element) => { 182 form_data.field_list.forEach((element) => {
211 - if (element.component_code === "page_header") { 183 + if (element.tag === "page_header") {
212 // 页眉组件 184 // 页眉组件
213 - const list = element.property_list; 185 + page_header = element;
214 - list.forEach((ele) => { 186 + } else if (element.tag === "page_commit") {
215 - page_header[ele["property_code"]] =
216 - ele.setting_value.length > 1 ? ele.setting_value : ele.setting_value[0];
217 - });
218 - } else if (element.component_code === "page_commit") {
219 // 提交按钮 187 // 提交按钮
220 - const list = element.property_list; 188 + page_commit = element;
221 - list.forEach((ele) => {
222 - page_commit[ele["property_code"]] =
223 - ele.setting_value.length > 1 ? ele.setting_value : ele.setting_value[0];
224 - });
225 } else { 189 } else {
226 page_form.push(element); 190 page_form.push(element);
227 } 191 }
......