فهرست منبع

增加协议管理

罗永浩 5 ماه پیش
والد
کامیت
43ce53ba86

+ 5 - 5
addons/admin/src/views/exam/component/TopicManager.vue

@@ -113,7 +113,7 @@
                     <el-input-number v-model="form.score" :min="1" :max="100"></el-input-number>
                 </el-form-item>
 
-                <el-form-item label="图片选项/答案" prop="answer_type" v-if="form.show_type === 2">
+                <el-form-item label="图片选项/答案" prop="answer_type">
                     <el-radio-group v-model="form.answer_type">
                         <el-radio :label="1">是</el-radio>
                         <el-radio :label="2">否</el-radio>
@@ -278,9 +278,9 @@ export default {
                 score: [
                     { required: true, message: '请输入分数', trigger: 'blur' }
                 ],
-                correct_answer: [
-                    { required: true, message: '请选择或输入正确答案', trigger: 'blur' }
-                ]
+                // correct_answer: [
+                //     { required: true, message: '请选择或输入正确答案', trigger: 'blur' }
+                // ]
             },
             options: ['', '', '', '', '', ''],
             currentTopic: null,
@@ -506,7 +506,7 @@ export default {
                     const res = await this.$http.post("/topics/edit", formData);
 
                     if (res.data.code === 0) {
-                        this.$message.success(this.isEdit ? '更新成功' : '添加成功');
+                        // this.$message.success(this.isEdit ? '更新成功' : '添加成功');
                         this.loadTopics();
                         this.cancelForm();
                         this.$emit('saved');

+ 20 - 3
addons/admin/src/views/system/article/components/ArticleForm.vue

@@ -47,7 +47,7 @@ export default {
     name: 'ArticleForm',
     components: { TinymceEditor },
     props: {
-        defaultType: { type: [Number, String], default: null },
+        defaultType: { type: [Number, String, Array], default: null },
         visible: { type: Boolean, default: false },
         defaultData: { type: Object, default: () => ({ status: 1, type: 1 }) },
     },
@@ -75,7 +75,12 @@ export default {
         },
         // 判断是否为智能问答类型
         isSmartReply() {
-            const currentType = this.defaultType || this.formData.type;
+            // 处理 defaultType 可能是 Number、String 或 Array 的情况
+            let currentType = this.defaultType || this.formData.type;
+            if (Array.isArray(this.defaultType)) {
+                // 如果是数组,使用第一个元素判断
+                currentType = this.defaultType.length > 0 ? this.defaultType[0] : this.formData.type;
+            }
             const b = currentType == 9;
             console.log('isSmartReply', b, this.defaultType)
             return b;
@@ -126,8 +131,20 @@ export default {
         save() {
             this.$refs.formRef.validate(valid => {
                 if (!valid) return
+
+                // 处理 defaultType 可能是 Number、String 或 Array 的情况
+                let typeValue = this.formData.type;
+                if (this.defaultType) {
+                    if (Array.isArray(this.defaultType)) {
+                        // 如果是数组,使用第一个元素
+                        typeValue = this.defaultType.length > 0 ? Number(this.defaultType[0]) : this.formData.type;
+                    } else {
+                        typeValue = this.defaultType;
+                    }
+                }
+
                 const loading = this.$loading({ lock: true })
-                this.$http.post('/article/edit', { ... this.formData, type: this.defaultType ? this.defaultType : this.formData.type })
+                this.$http.post('/article/edit', { ... this.formData, type: typeValue })
                     .then(res => {
                         loading.close()
                         if (res.data.code === 0) {

+ 32 - 11
addons/admin/src/views/system/article/components/list.vue

@@ -89,7 +89,7 @@ import ArticleForm from './ArticleForm.vue'
 import { mapGetters } from "vuex";
 export default {
   props: {
-    defaultType: { type: [Number, String], default: null },
+    defaultType: { type: [Number, String, Array], default: null },
     permissionMap: { type: Object, default: null },
   },
   name: "Sysarticle",
@@ -152,16 +152,28 @@ export default {
   mounted() {
     // 如果父组件传入 defaultType,则直接作为表格过滤条件并刷新表格
     if (this.defaultType) {
-      // 创建新对象,保证引用变化
-      this.table = {
-        ...this.table,
-        where: { ...this.table.where, type: Number(this.defaultType) }
+      // 处理 defaultType 可能是 Number、String 或 Array 的情况
+      let typeValue = null;
+      if (Array.isArray(this.defaultType)) {
+        // 如果是数组,直接使用数组(后端接口支持数组类型)
+        // 确保数组元素都是数字类型
+        typeValue = this.defaultType.length > 0 ? this.defaultType.map(t => Number(t)) : null;
+      } else {
+        typeValue = Number(this.defaultType);
+      }
+
+      if (typeValue !== null && (Array.isArray(typeValue) ? typeValue.length > 0 : true)) {
+        // 创建新对象,保证引用变化
+        this.table = {
+          ...this.table,
+          where: { ...this.table.where, type: typeValue }
+        }
+        // 通过设置 key 强制刷新整个表格组件
+        this.$nextTick(() => {
+          this.$refs.table.reload()
+          this.tableKey = Date.now()  // 新增 data 属性 tableKey
+        })
       }
-      // 通过设置 key 强制刷新整个表格组件
-      this.$nextTick(() => {
-        this.$refs.table.reload()
-        this.tableKey = Date.now()  // 新增 data 属性 tableKey
-      })
     }
   },
   computed: {
@@ -181,7 +193,16 @@ export default {
       return item ? item.name : '未知类型'
     },
     openCreate() {
-      this.editArticle = { status: 1, type: this.defaultType ? Number(this.defaultType) : 1 }
+      // 处理 defaultType 可能是 Number、String 或 Array 的情况
+      let typeValue = 1;
+      if (this.defaultType) {
+        if (Array.isArray(this.defaultType)) {
+          typeValue = this.defaultType.length > 0 ? Number(this.defaultType[0]) : 1;
+        } else {
+          typeValue = Number(this.defaultType);
+        }
+      }
+      this.editArticle = { status: 1, type: typeValue }
       this.showArticleForm = true
     },
     openEdit(article) {

+ 1 - 1
addons/admin/src/views/system/article/type-1.vue

@@ -1,5 +1,5 @@
 <template>
-  <articleList defaultType="1" :permissionMap="permissionMap">
+  <articleList :defaultType="1" :permissionMap="permissionMap">
   </articleList>
 </template>
 

+ 5 - 5
addons/admin/src/views/system/article/type-2.vue

@@ -1,5 +1,5 @@
 <template>
-  <articleList defaultType="1" :permissionMap="permissionMap"></articleList>
+  <articleList :defaultType="[2, 3, 4]" :permissionMap="permissionMap"></articleList>
 </template>
 
 <script>
@@ -13,10 +13,10 @@ export default {
   data() {
     return {
       permissionMap: {
-        delete: "exam:sdzb:daily:delete",
-        edit: "exam:sdzb:daily:edit",
-        add: "exam:sdzb:daily:add",
-        index: "exam:sdzb:daily:index",
+        delete: "sys:protocol:delete",
+        edit: "sys:protocol:edit",
+        // add: "sys:protocol:add",
+        index: "sys:protocol:index",
       }
     }
   }

+ 1 - 1
addons/admin/src/views/system/article/type-3.vue

@@ -1,5 +1,5 @@
 <template>
-  <articleList defaultType="1":permissionMap="permissionMap" ></articleList>
+  <articleList :defaultType="3" :permissionMap="permissionMap"></articleList>
 </template>
 
 <script>

+ 1 - 1
addons/admin/src/views/system/article/type-4.vue

@@ -1,5 +1,5 @@
 <template>
-  <articleList defaultType="1":permissionMap="permissionMap" ></articleList>
+  <articleList :defaultType="4" :permissionMap="permissionMap"></articleList>
 </template>
 
 <script>

+ 1 - 1
addons/admin/src/views/system/article/type-9.vue

@@ -1,5 +1,5 @@
 <template>
-  <articleList defaultType="9" :permissionMap="permissionMap">
+  <articleList :defaultType="9" :permissionMap="permissionMap">
   </articleList>
 </template>
 

+ 33 - 8
app/Services/Common/ArticleService.php

@@ -58,7 +58,31 @@ class ArticleService extends BaseService
     {
         $where = ['a.mark' => 1];
         $status = isset($params['status']) ? $params['status'] : 0;
-        $type = isset($params['type']) ? $params['type'] : 0;
+
+        // 处理type参数,支持单个值和数组类型
+        $type = isset($params['type']) ? $params['type'] : null;
+        if ($type !== null) {
+            // 如果是字符串"0"或数字0,转换为null(表示不过滤)
+            if ($type === '0' || $type === 0) {
+                $type = null;
+            } else if (is_string($type) && !is_array($type)) {
+                // 如果是字符串,尝试转换为数字
+                $type = is_numeric($type) ? (int)$type : null;
+            } else if (is_array($type)) {
+                // 如果是数组,确保所有元素都是数字类型,并过滤空值
+                $type = array_filter(array_map(function ($t) {
+                    return is_numeric($t) ? (int)$t : null;
+                }, $type));
+                // 如果数组为空,设置为null
+                if (empty($type)) {
+                    $type = null;
+                }
+            } else {
+                // 其他情况,转换为整数
+                $type = is_numeric($type) ? (int)$type : null;
+            }
+        }
+
         $cateId = isset($params['cate_id']) ? $params['cate_id'] : 0;
         $articleCateType = isset($params['article_cate_type']) ? $params['article_cate_type'] : 0;
 
@@ -71,25 +95,26 @@ class ArticleService extends BaseService
             ->where($where)
             ->where(function ($query) use ($type) {
                 if ($type && is_array($type)) {
+                    // 数组类型使用 whereIn
                     $query->whereIn('a.type', $type);
                 } else if ($type) {
+                    // 单个值使用 where
                     $query->where('a.type', $type);
                 }
             })
-            ->where(function ($query) use ($cateId,$articleCateType) {
-                if ($articleCateType && $articleCateType!=1) {
-                    if($cateId>0){
+            ->where(function ($query) use ($cateId, $articleCateType) {
+                if ($articleCateType && $articleCateType != 1) {
+                    if ($cateId > 0) {
                         $query->where('a.cate_id', $cateId);
-                    }else{
+                    } else {
                         $query->where('a.cate_id', '>', 0);
                     }
-
-                }else if($articleCateType==1){
+                } else if ($articleCateType == 1) {
                     $query->where('a.cate_id', 0);
                 }
             })
             ->where(function ($query) use ($articleCateType) {
-                if ($articleCateType>1) {
+                if ($articleCateType > 1) {
                     $query->where('ac.type', $articleCateType);
                 }
             })