Ver código fonte

Merge branch 'xf_dev' of http://192.168.101.4:3000/jiaxiaoqiang/JG-ADMIN-TEMP into xf_dev

lupeng 10 meses atrás
pai
commit
6056d63ea1

+ 4 - 4
src/api/station/index.ts

@@ -1,6 +1,6 @@
 import request from "@/utils/request";
 import { AxiosPromise } from "axios";
-import {Station, StationDevice} from "./types";
+import { Station, StationDevice } from "./types";
 
 /**
  * 修改工位
@@ -15,6 +15,7 @@ export function updateStation(data: Station) {
     data: data,
   });
 }
+
 export function bindStation(data: Station) {
   return request({
     url: "/api/v1/base/station/bind",
@@ -23,14 +24,13 @@ export function bindStation(data: Station) {
   });
 }
 
-
 /**
  * 工位绑定设备
  *
  * @param id
  * @param data
  */
-export function addStationDevice(data: StationDevice) {
+export function addStationDevice(data: object) {
   return request({
     url: "/api/v1/base/stationDevice/add",
     method: "post",
@@ -40,7 +40,7 @@ export function addStationDevice(data: StationDevice) {
 
 export function queryStationByLineId(lineId: any) {
   return request({
-    url: "/api/v1/base/station/queryStationByLineId/"+lineId,
+    url: "/api/v1/base/station/queryStationByLineId/" + lineId,
     method: "get",
   });
 }

+ 2 - 4
src/api/station/types.ts

@@ -5,7 +5,7 @@
  */
 
 export interface Station {
-  id?:number;
+  id?: number;
   //工位编码
   code?: string;
   //上级产线编码
@@ -13,10 +13,8 @@ export interface Station {
 
   //是否启用
   enable?: string;
-
 }
 
-
 /**
  *
  * 工位绑定设备参数
@@ -27,5 +25,5 @@ export interface StationDevice {
   //工位id
   stationId?: number;
   //设备编号
-  deviceNo?: string;
+  deviceNos?: string[];
 }

+ 23 - 6
src/components/CommonTable/index.vue

@@ -1,17 +1,17 @@
 <template>
   <el-dialog
     v-model="isShowTable"
+    :before-close="handleClose"
     :title="tableTitle"
     width="1200"
-    :before-close="handleClose"
   >
     <avue-crud
       ref="crudRef"
-      v-model:search="search"
       v-model="form"
+      v-model:page="page"
+      v-model:search="search"
       :data="data"
       :option="option"
-      v-model:page="page"
       @row-click="rowClick"
       @row-save="createRow"
       @row-update="updateRow"
@@ -26,7 +26,7 @@
     <template #footer>
       <div class="dialog-footer">
         <el-button @click="handleClose">取消</el-button>
-        <el-button type="primary" @click="onSelected"> 确定 </el-button>
+        <el-button type="primary" @click="onSelected"> 确定</el-button>
       </div>
     </template>
   </el-dialog>
@@ -45,6 +45,15 @@ const props = defineProps({
     default: "",
     type: String,
   },
+  multiple: {
+    default: false,
+    type: Boolean,
+  },
+  // 用于多选的返回值
+  multipleKey: {
+    default: "id",
+    type: String,
+  },
 });
 
 const isShowTable = ref(false);
@@ -92,6 +101,7 @@ const {
   commonConfig,
 } = useCrud({
   src: tableConfig[props.tableType].url,
+  multipleSelectKey: props.multipleKey,
 });
 const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
   Methords; //增删改查
@@ -99,7 +109,7 @@ const { selectionChange, multipleDelete } = Methords; //选中和批量删除事
 
 const crudRef = ref(null); //crudRef.value 获取avue-crud对象
 
-const commonTableEmits = defineEmits(["selectedSure"]);
+const commonTableEmits = defineEmits(["selectedSure", "selectMultipleSure"]);
 
 const calculateColumnWidth = (column) => {
   if (!column.label) {
@@ -124,6 +134,7 @@ onMounted(() => {
   option.value = Object.assign(option.value, {
     menu: false,
     highlightCurrentRow: true,
+    selection: props.multiple,
     addBtn: false,
     height: "500",
     overHidden: true,
@@ -145,6 +156,7 @@ watch(
     option.value = Object.assign(option.value, {
       menu: false,
       highlightCurrentRow: true,
+      selection: props.multiple,
       addBtn: false,
       height: "500",
       overHidden: true,
@@ -170,7 +182,12 @@ const handleClose = () => {
 };
 
 const onSelected = () => {
-  commonTableEmits("selectedSure", selectRowValue.value);
+  if (props.multiple) {
+    commonTableEmits("selectMultipleSure", toDeleteIds.value);
+  } else {
+    commonTableEmits("selectedSure", selectRowValue.value);
+  }
+
   isShowTable.value = false;
 };
 

+ 20 - 13
src/hooks/userCrud.ts

@@ -23,6 +23,8 @@ interface UseCrudConfig {
   params?: object;
   // 是否是编辑,如果是编辑调用更新,否则调用新增
   isEdit?: boolean;
+  //   用于多选选中后添加进入,toDeleteIds中的key值。
+  multipleSelectKey?: string;
 }
 
 export const useCrud = (config?: UseCrudConfig) => {
@@ -54,7 +56,7 @@ export const useCrud = (config?: UseCrudConfig) => {
   });
   /** 配置项结构 v-model */
   // defaults ?: AvueCrudDefaults;
-
+  // 多选返回的数组,命名是因为后来增加了很多功能,现在这个数组里面的值是根据multipleSelectKey来决定
   const toDeleteIds = ref<Array<string>>([]);
 
   const save = async (config?: UseCrudConfig) => {
@@ -102,7 +104,7 @@ export const useCrud = (config?: UseCrudConfig) => {
       handleSearchData();
       try {
         const res = await request({
-          url: commonConfig.value.dataListUrl ?? `${url.value}/page`,
+          url: commonConfig.value?.dataListUrl ?? `${url.value}/page`,
           method: "post",
           data: {
             pageNo: page.value.currentPage,
@@ -141,22 +143,25 @@ export const useCrud = (config?: UseCrudConfig) => {
           },
         });
         if (res?.data) {
-          if(res?.data instanceof Array){
-            data.value = res?.data || []
-            page.value.total = res?.data?.length || 0
-          }else{
+          if (res?.data instanceof Array) {
+            data.value = res?.data || [];
+            page.value.total = res?.data?.length || 0;
+          } else {
             data.value = res?.data?.records || [];
             for (let i = 0; i < data.value.length; i++) {
               data.value[i].$cellEdit = true;
-              if(data.value[i].children!=undefined&&data.value[i].children!=null&&data.value[i].children.length > 0 ){
-                for(let j=0;j < data.value[i].children.length; j++){
+              if (
+                data.value[i].children != undefined &&
+                data.value[i].children != null &&
+                data.value[i].children.length > 0
+              ) {
+                for (let j = 0; j < data.value[i].children.length; j++) {
                   data.value[i].children[j].$cellEdit = true;
                 }
               }
             }
             page.value.total = res?.data?.totalCount || 0;
           }
-
         }
         config?.done && config?.done();
       } catch (err) {
@@ -211,9 +216,9 @@ export const useCrud = (config?: UseCrudConfig) => {
         cancelButtonText: "取消",
         type: "warning",
       }).then(async () => {
-        if(row.children && row.children.length > 0 ){
-          ElMessage.error("请先解绑下级关系")
-          return
+        if (row.children && row.children.length > 0) {
+          ElMessage.error("请先解绑下级关系");
+          return;
         }
         try {
           const res = await request({
@@ -235,7 +240,9 @@ export const useCrud = (config?: UseCrudConfig) => {
     selectionChange: (rows?: any[]) => {
       toDeleteIds.value = [];
       rows?.forEach((element) => {
-        toDeleteIds.value.push(element.id);
+        toDeleteIds.value.push(
+          element[commonConfig.value?.multipleSelectKey ?? "id"]
+        );
       });
     },
 

+ 3 - 4
src/views/base/modeling/station/components/station-page.vue

@@ -33,6 +33,7 @@
     <CommonTable
       ref="ctableRef"
       :multiple="true"
+      multipleKey="deviceNo"
       tableTitle="设备列表"
       tableType="DEVICE"
       @select-multiple-sure="onSelectedFinish"
@@ -101,10 +102,8 @@ option.value = Object.assign(option.value, {
 });
 const props = defineProps({
   stationId: {
-    type: Number,
-    default: () => {
-      return 0;
-    },
+    type: String,
+    default: "",
   },
 });