Sfoglia il codice sorgente

全局表单2025-6-25

CaoGQ123 4 settimane fa
parent
commit
58c8c98979

+ 14 - 0
src/api/globalFormApi.js

@@ -81,6 +81,18 @@ export const font_form_add_api = (data) => {
     })
 }
 //全局表单-查看内容-列表-----------------------------------
+
+
+
+//上传图片 
+export const load_img_api = (data) => {
+    return request({
+        url: '/public/uploadFile',  
+        method: 'post',
+        data
+    })
+}
+
 export const up_table_api = (data) => {
     return request({
         url: '/form/updateGlobalTableData',  
@@ -88,6 +100,8 @@ export const up_table_api = (data) => {
         data
     })
 }
+
+
 export const cancel_table_api = (data) => {
     return request({
         url: '/form/delGlobalTableData', 

+ 101 - 37
src/views/tabbar/globalForm.vue

@@ -47,9 +47,18 @@
                         </el-table-column>
                         <el-table-column prop="table" label="表名" width="">
                         </el-table-column>
+
                         <el-table-column prop="website_name" label="网站名称" width="">
                         </el-table-column>
+                        
+                        <el-table-column prop="is_code" label="验证码" width="122">
+                            <template slot-scope="scope">
+                                {{ scope.row.is_code === 0 ? '未使用验证码' : '已使用验证码' }}
+                            </template>
+                        </el-table-column>
+
                         <el-table-column fixed="right" label="操作"  width="444">
+
                             <template slot-scope="scope">
                                 <div class="listBtnBox">
                                     <div class="listLookBtn" @click="goLook(scope.row.id, scope.row )">
@@ -99,12 +108,13 @@
             :close-on-click-modal="false" @close="cancelForm">
             <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                 <div class="dialogText">
-                    <el-form-item label="表单名:" prop="form_name">
+                    <el-form-item label="表单名:" prop="form_name" >
                         <el-input v-model="ruleForm.form_name" placeholder="请输入表单名">
                         </el-input>
                     </el-form-item>
                     <el-form-item label="表名:" prop="table_name">
-                        <el-input v-model="ruleForm.table_name" placeholder="请输入表名"></el-input>
+                        <el-input v-model="ruleForm.table_name" placeholder="请输入表名" :disabled="dialogName === '编辑表单'">
+                        </el-input>
                     </el-form-item>
                     <el-form-item label="网站名称:" prop="tabbarName_2">
                         <el-select v-model="ruleForm.tabbarName_2" :multiple="false" :multiple-limit="1" filterable remote
@@ -115,6 +125,19 @@
                             </el-option>
                         </el-select>
                     </el-form-item>
+ 
+                    <el-form-item label="验证码:" prop="use_captcha">
+                        <el-switch
+                             
+                            v-model="ruleForm.use_captcha"
+ 
+                            active-text="启用"
+                            inactive-text="停用"
+                            active-color="#5570F1"
+                            inactive-color="#DCDFE6">
+                        </el-switch>
+                    </el-form-item>
+
                 </div>
                 <div class="dialogBtn">
                     <el-button type="info" @click="cancelForm">取消</el-button>
@@ -182,6 +205,8 @@ export default {
             tabbarName: '', //单页名称
             website_id: "", //网站id
             ruleForm: {
+
+                use_captcha: 0, // 新增验证码开关 
                 form_name: '', //表单名
                 table_name: '', //表名
                 webName: '', //网站名称
@@ -212,6 +237,7 @@ export default {
             }).then(data => {
                 this.tableData = data.data.list
                 this.total =  data.data.total
+                 
             })
         },
         //1.2 删除内容
@@ -284,7 +310,7 @@ export default {
         //列表和分页相关 end ------------------------------------------------------------>
         //1.9 编辑
         goEdit(id, val) {
-            // console.log(id);
+            console.log("=================",val);
             this.dialogName = '编辑表单'
             this.activeid = id
             this.dialogTableVisible = true
@@ -294,6 +320,8 @@ export default {
             // 数据回显
             this.ruleForm.form_name = val.name      // 表单名
             this.ruleForm.table_name = val.table    // 表名
+            this.ruleForm.use_captcha = val.is_code == 1 ? true : false
+            
             this.webSiteName_id_2 = val.website_id  // 网站ID
               // 回显网站2名称
             this.ruleForm.tabbarName_2 = val.website_id  // 设置选中值
@@ -329,57 +357,93 @@ export default {
             this.ruleForm.webName = '' //关联网站名称
             this.ruleForm.tabbarName = '' //单页名称
             this.ruleForm.pageType = '' //页面类型
+            this.ruleForm.use_captcha = false //验证码    
+
+
         },
         // 弹出层相关方法
         submitForm(formName) {
+
             if(this.dialogName == "添加表单"){
-                add_table_api({// 提交表单add_table_api
-                    website_id: this.webSiteName_id_2, //网站id
-                    name: this.ruleForm.form_name, //表单名
-                    table: this.ruleForm.table_name, //表名 
-                    }).then(data =>{
-                        if (data.code == 200) {
-                            this.$message({
-                                message: '添加成功',
-                                type: 'success'
+             this.$refs[formName].validate((valid) => {
+                if (valid) {
+                    
+                        add_table_api({// 提交表单add_table_api
+                            website_id: this.webSiteName_id_2, //网站id
+                            name: this.ruleForm.form_name, //表单名
+                            table: this.ruleForm.table_name, //表名 
+                            is_code: this.ruleForm.use_captcha==true ? 1:0, //验证码
+                            }).then(data =>{
+                                if (data.code == 200) {
+                                    this.$message({
+                                        message: '添加成功',
+                                        type: 'success'
+                                    })
+                                    this.dialogTableVisible = false
+                                    this.getData()
+                                }
+                            }).catch(err =>{
+                                console.log(err);
                             })
-                            this.dialogTableVisible = false
-                            this.getData()
-                        }
-                    }).catch(err =>{
-                        console.log(err);
-                    })
-                    this.cancelForm()        
-            }
-            if(this.dialogName == "编辑表单"){
-                edit_table_api({// 编辑表单
-                    website_id: this.webSiteName_id_2, //网站id
-                    name: this.ruleForm.form_name, //表单名
-                    table: this.ruleForm.table_name, //表名 
-                    id: this.activeid, // 编辑时需要的id
-                    }).then(data =>{
-                        if (data.code == 200) {
-                            this.$message({
-                                message: '编辑成功',
-                                type: 'success'
+                            this.cancelForm()        
+                     
+                }else {
+                    this.$message.error('请填写所有必填项')
+                    return false
+                }
+            })
+            return
+        }
+
+        if(this.dialogName == "编辑表单"){
+
+              
+            this.$refs[formName].validate((valid) => {
+                if (valid) {
+                
+                        edit_table_api({// 编辑表单
+                            website_id: this.webSiteName_id_2, //网站id
+                            name: this.ruleForm.form_name, //表单名
+                            table: this.ruleForm.table_name, //表名 
+                            id: this.activeid, // 编辑时需要的id
+                            is_code: this.ruleForm.use_captcha==true ? 1:0, //验证码
+ 
+                            }).then(data =>{
+                                if (data.code == 200) {
+                                    this.$message({
+                                        message: '编辑成功',
+                                        type: 'success'
+                                    })
+                                    this.dialogTableVisible = false
+                                    this.getData()
+                                }
+                            }).catch(err =>{
+                                console.log(err);
                             })
-                            this.dialogTableVisible = false
-                            this.getData()
+                            this.cancelForm()        
+                            
+                        }else {
+                            this.$message.error('请填1写所有必填项')
+                            return false
                         }
-                    }).catch(err =>{
-                        console.log(err);
                     })
-                    this.cancelForm()        
-            }
+                    
+                }
         },
         //取消添加或编辑
         cancelForm() {
+            
+             this.$refs.ruleForm.resetFields() // 重置表单并清除验证状态
+              this.$refs.ruleForm.clearValidate() // 清除所有验证提示
+  
             this.dialogTableVisible = false
             this.webSiteName_id_2 = ""; //网站id
             this.ruleForm.form_name = "";//表单名
             this.ruleForm.table_name = ""; //表名 
             this.webSiteList_2 = []      // 清空网站2下拉列表数据
             this.ruleForm.tabbarName_2 = '' // 新增:清空表单中网站2的绑定值
+
+
         },
         //3.6 上传图片操作
         beforeAvatarUpload(file) {

+ 510 - 94
src/views/tabbar/globalFormDetail.vue

@@ -16,7 +16,30 @@
                             :width="head.width || ''">
                             <!-- 动态内容 -->
                             <template slot-scope="scope">
-                                {{ Object.values(scope.row).join(',').split(',')[index]  }}
+                                <template v-if="table_head[index].field_type !== '7'">
+                                    {{table_per_fun(table_head[index],Object.values(scope.row)[index])}}
+
+                                </template>
+                                <template v-if="table_head[index].field_type == '7'" >
+                                     
+
+                                    <div class="listLookBtn" @click="file_fun(table_per_fun(table_head[index],Object.values(scope.row)[index]))">
+                                        <i class="el-icon-view"></i>
+                                        预览
+                                    </div>
+                                    
+                                </template>
+
+                                <template v-if="table_head[index].field_type == '8'">
+                                     
+                                    <img class="img"
+                                        style="width:55px;height:55px;"
+                                        v-if="Object.values(scope.row).join(',').split(',')[index].trim()" 
+                                        :src="Object.values(scope.row).join(',').split(',')[index].trim() "
+                                        title="" alt=""
+                                    > 
+                                </template>
+
                             </template>
                         </el-table-column>
                         <!-- 保留操作列 -->
@@ -58,30 +81,131 @@
         <!--表格内容 end------------------------------------------------------------>
         <!-- 弹出框 编辑 start----------------------------------------------------------->
         <el-dialog :title="dialogName" :visible.sync="dialogTableVisible" width="50%" top="8vh"
-            :close-on-click-modal="false">
-            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
-                <div class="dialogText">
-                    <el-form-item 
-                        v-for="(head, index) in table_head" 
+        :close-on-click-modal="false">
+        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
+            <div class="dialogText">
+                <el-form-item 
+                v-for="(head, index) in table_head" 
                         :key="index"
-                        :label="head.title + ':'"
-                        :prop="head.field"
-                         :rules="[{ 
-                                    required: true, 
-                                    message: head.title + '不能为空', 
-                                    trigger: 'blur',
-                                    validator: (rule, value, callback) => {
-                                        if (!value || value.trim() === '') {
-                                            callback(new Error(head.title + '不能为空'))
-                                        } else {
-                                            callback()
-                                        }
-                                    }
-                                }]">
+                        :label="head.title"
+                        :prop="`field_${index}`"
+                        :rules="getValidationRules(head, index)">
+ 
+ 
+
+                        <!-- 文本文字1 -->
+                        <el-input 
+                            v-if="head.field_type==1"
+                            v-model="ruleForm[`field_${index}`]"
+                            :disabled="head.title === '编号' ? true : false"
+                            @blur="handleBlurValidation(head.title, ruleForm[`field_${index}`])">
+                        </el-input>
+ 
+                        <!-- 多行textarea 2-->
                         <el-input
-                            v-model="dialog_inp_arr[index]"
-                            @blur="handleBlurValidation(head.title, dialog_inp_arr[index])">
+                            v-if="head.field_type==2"
+                            v-model="ruleForm[`field_${index}`]"
+                            type="textarea"
+                            :autosize="{ minRows: 2, maxRows: 4 }"
+                            @blur="handleBlurValidation(head.title, ruleForm[`field_${index}`])"
+                        >
                         </el-input>
+
+                        <!-- 单选按钮 3 -->
+                        <el-radio-group 
+
+                            v-if="head.field_type==3" 
+                            v-model="ruleForm[`field_${index}`]"
+                            >
+                             
+                            <el-radio 
+                                v-for="(per_obj,per_index) in radio_arr_fun(head.option)" :key="per_index"
+                                
+                                :label="+per_obj[1]">
+                                  {{ per_obj[0] }}
+                                   
+                            </el-radio>
+                             
+                        </el-radio-group>
+ 
+                        <!-- 下拉选择 4 -->
+
+                        <el-select 
+                            v-if="head.field_type==4"
+                            placeholder="请选择"
+                            v-model="ruleForm[`field_${index}`]"
+                            
+                            style="width: 100%">
+                            <el-option
+                                v-for="(per_obj, per_index) in select_arr_fun(head.option)"
+                                :key="per_index"
+                                :label="per_obj.label"
+                                :value="per_obj.value">
+                            </el-option>
+                        </el-select>
+  
+                        <el-checkbox-group 
+                            v-if="head.field_type==5"
+                             v-model="ruleForm[`field_${index}`]"> 
+                            <el-checkbox 
+                                v-for="(per_obj, per_index) in head.option_value"
+                                :key="per_index"
+                                :label="per_index">
+                              {{ per_obj }}
+                            </el-checkbox>
+                        </el-checkbox-group>
+
+                        <!-- 日期选择器 6 -->
+                        <el-date-picker
+                            v-if="head.field_type==6"
+                            v-model="ruleForm[`field_${index}`]"
+                            type="date"
+                            value-format="yyyy-MM-dd"
+                            placeholder="选择日期"
+                            style="width: 100%">
+                        </el-date-picker>
+                        
+                        <!-- 上传单文件 7-->
+                          
+                       <template v-if="head.field_type==7">
+ 
+                                
+                                <button @click="file_fun(table_per_fun(head, ruleForm[`field_${index}`] ))">
+                                    预览
+                                </button>
+
+                       </template>  
+
+                        <!-- 上传img 8-->
+   
+                        <div class="uploaderBox" v-if="head.field_type==8" @mouseenter="hovering = true" @mouseleave="hovering = false">
+                            <el-upload 
+                            class="avatar-uploader"
+                            action="#"
+                            :show-file-list="false"
+                             :before-upload="(file) => beforeAvatarUpload(file, index)">
+  
+                                <img v-if="ruleForm[`field_${index}`]" :src="ruleForm[`field_${index}`]" class="avatar"> 
+
+                                <div v-else class="chooseImgDiv">
+                                    <div>
+                                    <img src="@/assets/public/upload/noImage.png">
+
+                                    <div>选择图片</div>
+                                    </div>
+                                </div>
+                                <input type="hidden" v-model="ruleForm[`field_${index}`]">
+                                <span class="photo_tips">推荐图片长宽比例为 16:9,大小不能超过 500 K。</span>
+                                <!-- <div v-if="true"  -->
+                                <div v-if="hovering && ruleForm[`field_${index}`]" 
+                                    class="delete-button"
+                                    @click="handleDelete(index)">
+                                    <i class="el-icon-delete"></i>
+                                </div>
+                            </el-upload>
+                        </div>
+  
+ 
                     </el-form-item>
                 </div>
                 <div class="dialogBtn">
@@ -98,14 +222,14 @@
 import tableTitle from './components/tableTitle.vue';
 //引入公用样式
 import '@/styles/global.less';
-import {  getFooterContent,up_table_api,look_table_api,cancel_table_api  } from '@/api/globalFormApi'
+import {  load_img_api,getFooterContent,up_table_api,look_table_api,cancel_table_api  } from '@/api/globalFormApi'
 //引入富文本编辑器
 import myEditor from '../../components/edit/myEditor.vue';
 export default {
     components: {
         tableTitle,//表格标题
         myEditor,
-    },
+    }, 
     data() {
         const validateEmpty = (rule, value, callback) => {
             if (value.length == 0) {
@@ -115,9 +239,20 @@ export default {
             }
         }
         return {
+             
+            checkbox_active_arr:[],//复选选中 
+            checkbox_selected_arr:[],//复选框选中
+            hovering: false,
+            imgUrl:"",
+            arr_1:[1,23,12,3],
             up_edit_obj:{},//编辑后提交的数据
-            dialog_inp_arr:[ ],
-            activeIndex: 0, // 新增当前操作行索引
+            ruleForm: {
+            },
+            rules: {
+                listTitle: [{ required: true, trigger: 'blur', validator: validateEmpty }],
+                contentTitle: [{ required: true, trigger: 'blur', validator: validateEmpty }],
+                contentDetail: [{ required: true, trigger: 'blur', validator: validateEmpty }],
+            },
             table_head:[],//列表头
             table_body:[],//列表内容
             tableDivTitle: "查看内容",  //列表标题
@@ -136,19 +271,25 @@ export default {
             listTitle: '', //网站名称id
             contentTitle: '', //广告位名称
             //弹框相关
-            ruleForm: {
-                // listTitle: '', //列表标题
-                // contentTitle: '', //内容标题
-                // contentDetail: '', //内容详情
-            },
-            rules: {
-                listTitle: [{ required: true, trigger: 'blur', validator: validateEmpty }],
-                contentTitle: [{ required: true, trigger: 'blur', validator: validateEmpty }],
-                contentDetail: [{ required: true, trigger: 'blur', validator: validateEmpty }],
-            }
+            activeIndex: 0, // 新增当前操作行索引
         }
     },
     methods: {
+ 
+
+        convertStringArray(strArray) {
+        try {
+            return strArray.map(item => {
+                if (typeof item === 'string' && /^\[.*\]$/.test(item)) {
+                    return JSON.parse(item.replace(/'/g, '"'));
+                }
+                return item;
+            });
+        } catch (e) {
+            console.error('数组转换失败:', e);
+            return strArray;
+        }
+    },
         //1.列表和分页相关 start ------------------------------------------------------------>
         //1.1 开始请求列表信息方法
         getData() {
@@ -162,6 +303,8 @@ export default {
                 this.total = data.data.total
                 this.table_head = data.data.tableFields//列表头
                 this.table_body = data.data.list//列表内容
+                 
+  
             })
         },
         //1.3 列表内容分页
@@ -198,17 +341,26 @@ export default {
         //列表和分页相关 end ------------------------------------------------------------>
         //1.7 编辑
         go_up(id, val,the_index) {
+            
+             
             this.up_edit_obj = this.table_body[the_index]
-            this.dialog_inp_arr = Object.values(this.table_body[the_index])
+            
+            
+             // 初始化 ruleForm
+            this.ruleForm = {}
+            const values = Object.values(this.table_body[the_index])
+            values.forEach((value, index) => {
+                // 将数字字符串转为数值类型(针对radio的label类型)
+                const convertedValue = typeof value === 'string' && !isNaN(value) ? Number(value) : value
+                this.$set(this.ruleForm, `field_${index}`, convertedValue)
+            })
+           
+           
             this.dialogName = '全局表单-编辑内容'
             this.activeid = id
             this.dialogTableVisible = true
             // console.log(id, val);
             this.activeIndex = the_index//点击的是第几个
-             // 添加字段映射(保持原有数组结构)
-            this.table_head.forEach((head, index) => {
-                this.$set(this.ruleForm, head.field, this.dialog_inp_arr[index])
-            })
         },
         //1.8 删除 
         go_cancel(id) {
@@ -234,64 +386,264 @@ export default {
                 })
             }).catch(() => {})
         },
-        // 弹出层相关方法
-        // 1.9 提交表单
-  submitForm(formName) {
-        const the_obj =this.table_body[0]
-        Object.keys(the_obj).forEach((key, index) => {
-            the_obj[key] = this.dialog_inp_arr[index]
-        });
-        the_obj.table_id = +this.$route.query.id;
-        const emptyFields = this.dialog_inp_arr
-            .map((value, index) => ({ 
-                index, 
-                field: this.table_head[index]?.title,
-                value 
-            }))
-            .filter(item => !item.value || item.value.toString().trim() === '');
-        if (emptyFields.length > 0) {
-            emptyFields.forEach(item => {
-                this.$message.error(`${item.field}:不能为空`);
+
+        // 单选按钮的str转obj
+        radio_arr_fun(the_str){
+             
+            let new_arr =[]
+            let the_arr = the_str.split('\n')
+            the_arr.forEach(( per_son_obj, index  ) => { 
+                new_arr[index] = per_son_obj.split('|')
+            })
+ 
+            return new_arr
+        },
+
+        // 下拉选择str转obj
+        select_arr_fun(the_str){
+             
+            let new_arr =[]
+            let the_arr = the_str.split('\n')
+             
+            the_arr.forEach(( per_son_obj, index  ) => { 
+                // new_arr[index] = per_son_obj.split('|')
+                let the_in_arr = per_son_obj.split('|')
+                let the_in_obj = {}
+                the_in_obj.label = the_in_arr[0]
+                the_in_obj.value = +the_in_arr[1]
+                 new_arr.push(the_in_obj)
+                
+            })
+             
+            return new_arr
+        },
+
+        // form 里复选框选项处理(与radio_arr_fun类似)
+        checkbox_arr_fun(the_index, the_str,active_num_arr,all_obj) {
+
+            let checkbox_strValue = String(active_num_arr || "").replace(/[\[\]]/g, '');
+            active_num_arr = checkbox_strValue.split(',').filter(Boolean).map(Number);
+            let act_label_arr = []//选中的label-arr
+            active_num_arr.forEach(( per_obj ) => { 
+                act_label_arr.push(all_obj[per_obj])
+            }) 
+            const new_all_arr = Object.values(all_obj || {});    
+
+  
+            this.ruleForm[`field_${the_index}`]=act_label_arr 
+             
+
+            return new_all_arr
+        },
+ 
+        table_per_fun(the_head,the_obj){//判断table是否是图片
+
+
+            if(the_head.field_type == '1'){//文字
+                return the_obj 
+            }
+            if(the_head.field_type == '2'){//多行文本
+                return the_obj 
+            }
+
+            if(the_head.field_type == '3'){//单选框
+                return the_head.option_value[the_obj] 
+            }
+
+            if(the_head.field_type == '4'){//下拉选择
+                return the_head.option_value[+the_obj] 
+            }
+            if(the_head.field_type == '5'){//复选框
+                let strValue = String(the_obj || "").replace(/[\[\]]/g, '')
+                let arr_in = strValue.split(',').filter(Boolean).map(Number)
+                let the_new_arr = []
+                arr_in.forEach(( per_obj ) => { 
+                    the_new_arr.push(the_head.option_value[per_obj])
+                })
+
+                return the_new_arr.join('-') 
+            }
+
+            if(the_head.field_type == '6'){//日期
+                return the_obj 
+            }
+            
+            if(the_head.field_type == '7'){//单文件
+                return the_obj
+            }
+
+ 
+
+        },
+
+          file_fun(fileUrl) {
+                if (!fileUrl) {
+                    this.$message.error('文件路径无效');
+                    return;
+                }
+                // 直接在新标签页打开文件链接
+                window.open(fileUrl, '_blank');
+            },
+
+
+        //上传img
+        beforeAvatarUpload(file,index) {
+             
+            const isJPG = file.type === 'image/jpeg';
+            const isPNG = file.type === 'image/png';
+            const isLt2M = file.size / 1024 / 1024 < 2;
+
+            if (!isJPG && !isPNG) {
+            this.$message.error('上传缩略图只能是 JPG 或 PNG 格式!');
+            return false;
+            }
+            if (!isLt2M) {
+            this.$message.error('上传缩略图大小不能超过 2MB!');
+            return false;
+            }
+
+            const formData = new FormData();
+            formData.append('file', file);
+
+            load_img_api(formData).then(res => {
+            if (res.code === 200) {
+                this.$message.success('上传成功');
+                this.$set(this.ruleForm, `field_${index}`, res.data.imgUrl);  // 使用index更新对应位置
+            } else {
+                this.$message.error(res.message || '上传失败');
+            }
             });
-            return;
-        }
-        this.$refs[formName].validate((valid) => {
-            if (valid) {
-                // 验证通过后的提交逻辑
-                up_table_api({
-                    ...the_obj  //展开
-                }).then(res => {
-                    if (res.code === 200) {
-                        this.$message.success('提交成功');
-                        this.dialogTableVisible = false;
-                        this.getData();
+
+
+            return false;
+        },
+
+        // 删除图片
+        handleDelete(index) {
+             this.$set(this.ruleForm, `field_${index}`, '');
+            
+        },
+                // 弹出层相关方法
+                // 1.9 提交表单
+        submitForm(formName) {
+                // 转换复选框数据(数组转字符串)
+                const convertedData = this.table_head.map((head, index) => {
+                    const value = this.ruleForm[`field_${index}`];
+                    if (head.field_type === 5) {
+                        return Array.isArray(value) && value.length === 1 
+                            ? value[0] 
+                            : Array.isArray(value) ? value.join(',') : value;
+                    }
+                    return value;
+                });
+                
+                // 使用转换后的数据提交
+                const the_obj = this.table_body[0];
+                Object.keys(the_obj).forEach((key, index) => {
+                    the_obj[key] = convertedData[index];
+                });
+                the_obj.table_id = +this.$route.query.id;
+                
+                this.$refs[formName].validate((valid) => {
+                    if (valid) {
+                        // 验证通过后的提交逻辑
+                         
+
+                        up_table_api({
+                            ...the_obj  //展开
+                        }).then(res => {
+                            if (res.code === 200) {
+                                this.$message.success('提交成功');
+                                this.dialogTableVisible = false;
+                                this.getData();
+                            } else {
+                                this.$message.error(res.message || '提交失败');
+                            }
+                        });
                     } else {
-                        this.$message.error(res.message || '提交失败');
+                        this.$message.error('请填写所有必填项');
+                        return false;
                     }
                 });
-            } else {
-                this.$message.error('请填写所有必填项');
-                return false;
-            }
-        });
-    },
-        //取消
-        cancelForm() {
-            this.dialogTableVisible = false
-        },
-        handleBlurValidation(fieldName, value) {
-            if (!value || value.trim() === '') {
-                this.$message.error(`${fieldName}:不能为空`);
-            }
+                
+            },
+                //取消
+                cancelForm() {
+                    this.dialogTableVisible = false
+                },
+                handleBlurValidation(fieldName, value) {
+                    if (!value || value.trim() === '') {
+                        this.$message.error(`${fieldName}:不能为空`);
+                    }
+                },
+                getValidationRules(head, index) {
+                    const rules = [];
+                    
+                    // 调试信息
+                    // console.log(`字段 ${head.title}:`, {
+                    //     is_check: head.is_check,
+                    //     regular: head.regular,
+                    //     field_type: head.field_type
+                    // });
+                    
+                    // 检查是否需要验证:is_check 为 1 且有 regular 正则表达式
+                    if ((head.is_check === 1 || head.is_check === '1') && head.regular) {
+                        // console.log(`为字段 ${head.title} 添加验证规则:`, head.regular);
+                        rules.push({
+                            required: true,
+                            message: head.regular_error || `${head.title}格式不正确`,
+                            trigger: 'blur',
+                            validator: (rule, value, callback) => {
+                                // console.log(`验证字段 ${head.title}:`, value, '类型:', typeof value);
+                                // 空值检查
+                                if (!value || value.toString().trim() === '') {
+                                    callback(new Error(head.regular_error || `${head.title}不能为空`));
+                                    return;
+                                }
+                                
+                                // 正则验证
+                                try {
+                                    // 处理正则表达式字符串格式
+                                    let regexPattern = head.regular;
+                                    
+                                    // 如果正则表达式包含 / 分隔符,需要提取模式部分
+                                    if (regexPattern.startsWith('/') && regexPattern.includes('/')) {
+                                        const lastSlashIndex = regexPattern.lastIndexOf('/');
+                                        regexPattern = regexPattern.substring(1, lastSlashIndex);
+                                    }
+                                    
+                                    // console.log(`处理后的正则表达式:`, regexPattern);
+                                    const reg = new RegExp(regexPattern);
+                                    const testResult = reg.test(value);
+                                    // console.log(`正则测试结果:`, testResult, `值: "${value}"`, `正则: ${regexPattern}`);
+                                    
+                                    if (!testResult) {
+                                        callback(new Error(head.regular_error || `${head.title}格式不正确`));
+                                    } else {
+                                        callback();
+                                    }
+                                } catch (e) {
+                                    console.error('正则表达式错误:', e);
+                                    callback(new Error('校验规则配置错误'));
+                                }
+                            }
+                        });
+                    }
+                    
+                    return rules;
+                }
+            },
+
+            mounted() {
+                // console.log(this.$route.query.id);
+                this.tabbarId = this.$route.query.id
+                this.tabbarType = this.$route.query.type
+                this.getData() //获取数据
+            },
+
+        
+
         }
-    },
-    mounted() {
-        // console.log(this.$route.query.id);
-        this.tabbarId = this.$route.query.id
-        this.tabbarType = this.$route.query.type
-        this.getData() //获取数据
-    },
-}
 </script>
 <style scoped lang="less">
 input[aria-hidden=true] {
@@ -520,4 +872,68 @@ input[aria-hidden=true] {
 .dialog-footer {
     margin: 0 auto;
 }
+
+.uploaderBox {
+  position: relative;
+  .avatar-uploader {
+    border: 1px dashed #d9d9d9;
+    border-radius: 6px;
+    cursor: pointer;
+    position: relative;
+    overflow: hidden;
+    width: 178px;
+    height:auto;
+    
+    &:hover {
+      border-color: #409EFF;
+    }
+    
+    .avatar {
+      width: 100%;
+      height: 177px;
+      display: block;
+    }
+     
+
+    .chooseImgDiv {
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      height: 100%;
+      color: #8c939d;
+      width:100%;
+      img {
+        width: 60px;
+        height: 60px;
+        margin:10px auto 0;
+
+      }
+    }
+  }
+  
+  .delete-button {
+    position: absolute;
+    right: 33%;
+    top: 33%;
+    color: #fff;
+    background: rgba(0,0,0,0.5);
+    padding: 5px;
+    border-radius: 50%;
+    cursor: pointer;
+     
+    width:33%;height: 60px;
+  }
+  .delete-button .el-icon-delete{
+    font-size: 33px;
+    margin-top:  6px;
+  }
+
+  .photo_tips {
+    display: block;
+    margin-top: 10px;
+    font-size: 12px;
+    color: #999;
+    line-height:22px;
+  }
+}
 </style>

+ 83 - 90
src/views/tabbar/globalFormFont.vue

@@ -56,6 +56,7 @@
                     <el-form-item label="显示名称:" prop="field_name_show">
                         <el-input 
                             v-model="ruleForm.field_name_show" 
+                            :disabled="dialogName === '修改字段'"
                             placeholder="请输入"
                             clearable>
                         </el-input>
@@ -71,34 +72,55 @@
                             </el-option>
                         </el-select>
                     </el-form-item>
+ 
                     <el-form-item label="选项列表:" prop="field_textarea">
                         <el-input
                         type="textarea"
                         :rows="2"
                         placeholder="请输入内容"
-                        v-model="ruleForm.field_textarea">
+                        v-model="ruleForm.field_textarea"
+                        :disabled="ruleForm.field_type >= 3 && ruleForm.field_type <= 5 ? false : true"
+                        >
                         </el-input>
                     </el-form-item>
+
+
                     <el-form-item label="长度:" prop="field_length">
                         <el-input 
                         placeholder="请输入"
                         v-model="ruleForm.field_length">
                         </el-input>
                     </el-form-item>
-                    <el-form-item label="否校验:" prop="field_switch">
+
+                    <el-form-item label="是否校验:" prop="field_switch">
                         <el-switch
                             v-model="ruleForm.field_switch"
-                            active-text="校验"
-                            inactive-text="不校验"
                             :active-value="1"
-                            :inactive-value="0">
+                            :inactive-value="0"
+                            @change="handleSwitchChange"
+                            >
                         </el-switch>
                     </el-form-item>
+ 
+ 
+                    <el-form-item label="校验内容:" prop="field_regular" 
+                        :rules="[
+                            { 
+                                required: ruleForm.field_switch === 1, 
+                                message: '请输入正则表达式', 
+                                trigger: 'blur' 
+                            } 
+                        ]">
+                        <el-input 
+                            v-model="ruleForm.field_regular" 
+                            placeholder="请输入正则表达式,例如:/^\d+$/" 
+                            :disabled="ruleForm.field_switch !== 1">
+                        </el-input>
+                    </el-form-item>
+
                     <el-form-item label="后端是否展示:" prop="field_switch_backend">
                         <el-switch
                             v-model="ruleForm.field_switch_backend"
-                            active-text="校验"
-                            inactive-text="不校验"
                             :active-value="1"
                             :inactive-value="0">
                         </el-switch>
@@ -106,8 +128,6 @@
                     <el-form-item label="前端是否展示:" prop="field_switch_web">
                         <el-switch
                             v-model="ruleForm.field_switch_web"
-                            active-text="校验"
-                            inactive-text="不校验"
                             :active-value="1"
                             :inactive-value="0">
                         </el-switch>
@@ -161,6 +181,9 @@ export default {
             tabbarName: '', //单页名称
             website_id: "", //网站id
             field_type_arr:[],
+            reg_inp_masg:"",//inp下的校验内容=提示
+
+
             ruleForm: {
                 field_recive_id: this.$route.query.id, //表id   this.$route.query.id,   table_id
                 field_name: '', //字段名称  field_name
@@ -172,8 +195,12 @@ export default {
                 field_switch: 0, // 新增校验开关,默认0不校验   is_check
                 field_switch_backend: 0, //后端是否展示 0:不展示 1:展示   admin_display
                 field_switch_web: 0, //前端是否展示 0:不展示 1:展示   home_display
+
+                field_regular: '', // 新增正则表达式字段
+
             },
             rules: {
+
                  field_name: [
                     { 
                         required: true, 
@@ -194,6 +221,21 @@ export default {
                     { type: 'number', message: '必须为数字值', trigger: 'blur',transform: value => Number(value) },
                     { type: 'number', min: 1, max: 255, message: '长度必须在1-255之间', trigger: 'blur',required: true },
                 ],
+
+                field_regular: [{ 
+                    required: true, 
+                    message: '校验内容不能为空', 
+                    trigger: 'blur',
+                    validator: (rule, value, callback) => {
+                        if (this.ruleForm.field_switch === 1 && !value) {
+                            callback(new Error('校验内容不能为空'))
+                        } else {
+                            callback()
+                        }
+                    }
+                }]
+            
+            
             }
         }
     },
@@ -288,12 +330,15 @@ export default {
         },
         //1.9 编辑
         goEdit(id, val) {
-            // console.log(id);
+            console.log("--------------------",id, val);
             this.dialogName = '修改字段'
             this.activeid = id
             this.dialogTableVisible = true
             this.disabled = true
-             this.ruleForm = {
+             
+            this.reg_inp_masg = val.regular
+
+            this.ruleForm = {
                 field_name: val.field_name,
                 field_name_show: val.title,
                 field_type: +val.field_type,
@@ -301,11 +346,14 @@ export default {
                 field_length: val.length,
                 field_switch: val.is_check,
                 field_switch_backend: val.admin_display,
-                field_switch_web: val.home_display
+                field_switch_web: val.home_display,
+                field_regular: val.regular,
+                field_regular_message: "请输入正则表达式如:"+val.regular,
             }
         },
         //1.7 添加
         addWebsite() {
+            console.log("添加字段---------");
             this.dialogTableVisible = true
             this.dialogName = "添加字段"
             this.disabled = false
@@ -319,16 +367,28 @@ export default {
                 field_length: '',
                 field_switch: 0,
                 field_switch_backend: 0,
-                field_switch_web: 0
+                field_switch_web: 0,
+                // field_regular: this.regular,
+                // field_regular_message: "请输入正则表达式如:"+this.regular,
             }
         },
+
+
+         handleSwitchChange(val) {
+        this.$nextTick(() => {
+            this.$refs.ruleForm.validateField('field_regular')
+        })
+    },
         // 弹出层相关方法
         // 提交添加字段
         submitForm(formName) {
-            if (this.dialogName == '修改字段') {
+            if (this.dialogName  == '修改字段') {
                 // 提交前验证所有字段
                 this.$refs[formName].validate((valid) => {
+
+
                     if (valid) {
+                        console.log("修改字段-------", this.ruleForm);
                         font_form_edit_api({
                             table_id: this.$route.query.id,
                             field_name: this.ruleForm.field_name,
@@ -339,7 +399,8 @@ export default {
                             is_check: this.ruleForm.field_switch,
                             admin_display: this.ruleForm.field_switch_backend,
                             home_display: this.ruleForm.field_switch_web,
-                            id: this.activeid
+                            id: this.activeid,
+                            regular: this.ruleForm.field_regular,
                             // id: this.$route.query.id,
                         }).then(data => {
                                 if (data.code == 200) {
@@ -349,6 +410,8 @@ export default {
                                 })
                                 this.dialogTableVisible = false
                                 this.getData()
+
+                                
                             } else if (data.code == 0) {
                                 this.$message({
                                     message: data.message,
@@ -366,7 +429,7 @@ export default {
                             }
                         })
                     } else {
-                        // this.$message.error('请填写所有必填字段!');
+                        this.$message.error('请填写所有必填字段!');
                         return false;
                     }
                 });
@@ -410,85 +473,15 @@ export default {
                             }
                         })
                     } else {
-                        // this.$message.error('请填写所有必填字段!');
+                        this.$message.error('请填写所有必填字段!');
                         return false;
                     }
                 });
             }
+
+
         },
-        // submitForm(formName) {
-        //     return
-        //     this.$refs[formName].validate((valid) => {
-        //         if (valid) {
-        //             console.log('submit!');
-        //         } else {
-        //             console.log('error submit!!');
-        //             return false;
-        //         }
-        //     });
-        //     if (this.dialogName == "添加") {
-        //         getTemplateClass({
-        //             website_id: this.website_id,
-        //             name: this.ruleForm.tabbarName,
-        //             type: this.ruleForm.pageType,
-        //         }).then(data => {
-        //             console.log(data);
-        //             if (data.code == 200) {
-        //                 this.$message({
-        //                     message: '添加成功',
-        //                     type: 'success'
-        //                 })
-        //                 this.dialogTableVisible = false
-        //                 this.getData()
-        //             } else if (data.code == 0) {
-        //                 this.$message({
-        //                     message: data.message,
-        //                     type: 'error'
-        //                 })
-        //                 this.dialogTableVisible = true
-        //                 return
-        //             } else {
-        //                 this.$message({
-        //                     message: data.message,
-        //                     type: 'error'
-        //                 })
-        //                 this.dialogTableVisible = true
-        //                 return
-        //             }
-        //         })
-        //     }
-        //     if (this.website_id == '') {
-        //         this.$message({
-        //             message: '请输入并选择网站名称',
-        //             type: 'error'
-        //         })
-        //         this.dialogVisible = true
-        //     }
-        //     if (this.dialogName == "编辑") {
-        //         upFooterCategory({
-        //             website_id: this.website_id,
-        //             name: this.ruleForm.tabbarName,
-        //             id: this.activeid
-        //         }).then(data => {
-        //             console.log(data);
-        //             if (data.code == 200) {
-        //                 this.$message({
-        //                     message: '编辑成功',
-        //                     type: 'success'
-        //                 })
-        //                 this.dialogTableVisible = false
-        //             }
-        //             if (data.code == 0) {
-        //                 this.$message({
-        //                     message: data.message,
-        //                     type: 'error'
-        //                 })
-        //                 this.dialogTableVisible = true
-        //             }
-        //             this.getData()
-        //         })
-        //     }
-        // },
+
         //取消添加或编辑
         cancelForm() {
             this.dialogTableVisible = false