Explorar o código

一键绑定所有商户号对应的小程序

xw hai 3 días
pai
achega
64d0961067

+ 9 - 0
src/api/merchantAppConfig/merchantAppConfig.js

@@ -51,3 +51,12 @@ export function exportMerchantAppConfig(query) {
     params: query
   })
 }
+
+// 批量绑定小程序
+export function batchBindMiniProgram(ids) {
+  return request({
+    url: '/course/playSourceConfig/batchBindMerchantConfig',
+    method: 'post',
+    data: { ids }
+  })
+}

+ 6 - 0
src/views/course/coursePlaySourceConfig/index.vue

@@ -849,6 +849,12 @@ export default {
           }else{
             this.form.setCompanyIds = "";
           }
+          
+          if (this.form.customAuthEnabled === 0) {
+            this.form.miniAppAuthType = null;
+            this.form.userCourseAuthDomain = null;
+          }
+          
           console.log(this.form);
           if (this.form.id != null) {
             update(this.form).then(response => {

+ 96 - 5
src/views/his/merchantAppConfig/index.vue

@@ -73,6 +73,17 @@
           v-hasPermi="['merchantAppConfig:merchantAppConfig:add']"
         >新增</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="primary"
+          icon="el-icon-link"
+          size="mini"
+          :disabled="multiple"
+          :loading="batchBindLoading"
+          @click="handleBatchBindMiniProgram"
+          v-hasPermi="['course:playSourceConfig:bind']"
+        >{{ batchBindButtonText }}</el-button>
+      </el-col>
 <!--      <el-col :span="1.5">-->
 <!--        <el-button-->
 <!--          type="success"-->
@@ -109,8 +120,8 @@
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
-    <el-table border v-loading="loading" :data="merchantAppConfigList" @selection-change="handleSelectionChange">
-<!--      <el-table-column type="selection" width="55" align="center" />-->
+    <el-table ref="merchantAppConfigTable" border v-loading="loading" :data="merchantAppConfigList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="主键ID" align="center" prop="id" />
       <el-table-column label="商户号" align="center" prop="merchantId" />
       <el-table-column label="商户类型" align="center" prop="merchantType">
@@ -330,17 +341,19 @@
 </template>
 
 <script>
-import { listMerchantAppConfig, getMerchantAppConfig, delMerchantAppConfig, addMerchantAppConfig, updateMerchantAppConfig, exportMerchantAppConfig } from "@/api/merchantAppConfig/merchantAppConfig";
+import { listMerchantAppConfig, getMerchantAppConfig, delMerchantAppConfig, addMerchantAppConfig, updateMerchantAppConfig, exportMerchantAppConfig, batchBindMiniProgram } from "@/api/merchantAppConfig/merchantAppConfig";
 import { listAll } from "@/api/course/coursePlaySourceConfig";
 
 export default {
   name: "MerchantAppConfig",
   data() {
     return {
-      // 罩层
+      // 罩层
       loading: true,
-      // 导出罩层
+      // 导出罩层
       exportLoading: false,
+      // 批量绑定加载状态
+      batchBindLoading: false,
       // 选中数组
       ids: [],
       // 非单个禁用
@@ -408,6 +421,18 @@ export default {
       }
     };
   },
+  computed: {
+    // 批量绑定按钮文案
+    batchBindButtonText() {
+      if (this.batchBindLoading) {
+        return '绑定中...';
+      }
+      if (this.ids && this.ids.length > 0) {
+        return `批量绑定小程序(${this.ids.length})`;
+      }
+      return '批量绑定小程序';
+    }
+  },
   created() {
 
     this.getDicts("sys_normal_disable").then(response => {
@@ -732,6 +757,72 @@ export default {
           this.download(response.msg);
           this.exportLoading = false;
         }).catch(() => {});
+    },
+    /** 批量绑定小程序 */
+    handleBatchBindMiniProgram() {
+      // 1. 检查是否有选中的记录
+      if (!this.ids || this.ids.length === 0) {
+        this.$message.warning('请先选择商户配置');
+        return;
+      }
+      
+      // 2. 显示确认对话框
+      this.$confirm(
+        `确定要将选中的 ${this.ids.length} 个商户配置绑定到对应的小程序吗?系统将自动查找匹配的小程序进行绑定。`,
+        '批量绑定确认',
+        {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }
+      ).then(() => {
+        // 3. 显示loading状态
+        this.batchBindLoading = true;
+        // 4. 调用后端接口
+        return batchBindMiniProgram(this.ids);
+      }).then(response => {
+        // 5. 成功处理:显示详细的绑定结果
+        this.batchBindLoading = false;
+        
+        // 使用后端返回的详细消息
+        const message = response.msg || '绑定成功';
+        
+        // 根据返回的code判断是否完全成功
+        if (response.code === 200) {
+          this.$message({
+            type: 'success',
+            message: message,
+            duration: 5000,
+            showClose: true
+          });
+        } else {
+          // 部分成功或其他情况
+          this.$message({
+            type: 'warning',
+            message: message,
+            duration: 5000,
+            showClose: true
+          });
+        }
+        
+        // 刷新列表
+        this.getList();
+        // 清空勾选
+        this.$refs.merchantAppConfigTable && this.$refs.merchantAppConfigTable.clearSelection();
+      }).catch(error => {
+        // 6. 失败处理:显示详细的失败原因
+        this.batchBindLoading = false;
+        
+        // 如果有错误信息,显示详细的失败原因
+        if (error && error.msg) {
+          this.$message({
+            type: 'error',
+            message: error.msg,
+            duration: 5000,
+            showClose: true
+          });
+        }
+      });
     }
   }
 };