Просмотр исходного кода

人员数据,改为一个接口获取

洪海涛 4 лет назад
Родитель
Сommit
c2ff77f24d

+ 1 - 0
src/api/qualityMonthlyReport/edit.js

@@ -6,6 +6,7 @@ import { projectManagementUrl, ldapServer } from '@/apiConfig/api'
 export function getMonthlyReport(reportId) {
   return request({
     url: projectManagementUrl + '/monthlyReport/get',
+    // url: 'http://localhost:9528/data.json',
     method: 'get',
     timeout: '10000',
     params: {

+ 46 - 7
src/store/modules/monthlyReport/edit/index.js

@@ -15,6 +15,7 @@ import {
   updateSubReport,
   pullDataAgain
 } from '@/api/qualityMonthlyReport/edit'
+// import { memberQueryMemberInfoByIDAPorName } from '@/api/projectIndex'
 import { getAvaliableInfo, getMonthlyReportVersion } from '@/api/qualityMonthlyReport'
 
 import {
@@ -30,6 +31,7 @@ import {
 import { message } from '@/utils/mesDebounce'
 
 import _ from 'lodash'
+import { getListPerson } from '@/api/onlineproblem'
 
 export default {
   /* 月报编辑 */
@@ -51,10 +53,12 @@ export default {
     subTabsActive: [], // 当前页签中所有已切换的数据
     domKeys: [], // 记录所有元素区域的唯一标识
     selectEnum: [], // 部门数据
-    userNames: [], // 人员数据
+    userNames: {}, // 人员数据
+    peopleLists: [], // 人员账号数据
     subTitle: '新建月报',
     subReportName: '',
     subReportInfo: null, // 为回退时,当前页面为查看完整时,无法获取子月报数据情况设置
+    timeout: null, // 函数防抖/节流
     offsetList: [],
     /**
      * 用户身份权限编号
@@ -158,14 +162,15 @@ export default {
       if (tabsActive) {
         state.tabsActive = `tab_${tabsActive}`
       }
-      // state.tabPageData = setReportData(tabPageData)
-      const { newObj, domKeys } = setReportData(
+      const { newObj, domKeys, peopleLists } = setReportData(
         tabPageData
           ? tabPageData.reportCatalog
           : state.reportData[0].reportCatalog
       )
       state.tabPageData = newObj
       state.domKeys = domKeys
+      console.log(peopleLists, 171)
+      state.peopleLists = peopleLists
     },
     // 切换页面之后数据维护
     TAB_ACTIVE_CHANGE(state, tabsActive) {
@@ -192,13 +197,15 @@ export default {
       state.reportData = [...reportData]
       // console.log(state.reportData)
       // 对新数据进行转换
-      const { newObj, domKeys } = setReportData(
+      const { newObj, domKeys, peopleLists } = setReportData(
         newTabPageData.reportCatalog,
         108
       )
       state.tabsActive = `tab_${newTabsActive}`
       state.tabPageData = newObj
       state.domKeys = domKeys
+      state.peopleLists = peopleLists
+      console.log(peopleLists)
       // 页面恢复待编辑状态
       state.editKeys = []
       // 子页面页签切换,清空原来的tabs选中状态
@@ -356,7 +363,9 @@ export default {
       state.subTabsActive = [] // 当前页签中所有已切换的数据
       state.domKeys = [] // 记录所有元素区域的唯一标识
       state.selectEnum = [] // 部门数据
-      state.userNames = [] // 人员数据
+      state.userNames = {} // 人员数据
+      state.peopleLists = [] // 人员账号数据
+      state.timeout = null // 函数防抖/节流
       state.subTitle = '新建月报'
       state.subReportName = ''
       state.subReportInfo = null // 为回退时,当前页面为查看完整时,无法获取子月报数据情况设置
@@ -379,7 +388,7 @@ export default {
     // tabPageData
     SET_TAB_PAGE_DATA(state, { data, id, tabsActive }) {
       // 对新数据进行转换
-      const { newObj, domKeys } = setReportData(
+      const { newObj, domKeys, peopleLists } = setReportData(
         {
           children: _.cloneDeep(data)
         },
@@ -391,6 +400,8 @@ export default {
       // console.log(365, state.tabPageData)
       state.tabPageData = newObj
       state.domKeys = domKeys
+      state.peopleLists = peopleLists
+      console.log(402, peopleLists)
       // 页面恢复待编辑状态
       state.editKeys = []
       // 子页面页签切换,清空原来的tabs选中状态
@@ -589,6 +600,15 @@ export default {
           })
         }
       }
+    },
+    /**
+     * 设置人员账号
+     * @param state  数据源
+     * @param people ['honghaitao_v'] 人员账号数组
+     * @constructor
+     */
+    SET_PEOPLELISTS(state, people) {
+      state.peopleLists = Array.from(new Set([...state.peopleLists, ...people]))
     }
   },
   actions: {
@@ -620,6 +640,7 @@ export default {
           commit('INIT_PAGE_DATA', { ...res.data })
           commit('INIT_TAB_PAGE_DATA', subActive && `tab_${subActive}`)
           commit('SET_LOADING', false)
+          dispatch('initPeople')
         }
       }
     },
@@ -634,7 +655,7 @@ export default {
       }
     },
     // 获取查看月报数据
-    async getSubReportData({ commit, state }, { id, subReportId, tabsActive }) {
+    async getSubReportData({ dispatch, commit, state }, { id, subReportId, tabsActive }) {
       const { pageType } = state
       let params = {}
       const method =
@@ -679,6 +700,7 @@ export default {
             id: pageType.search(/All/) > -1 ? `${id}` : `${res.data.parentId}`,
             name: pageType.search(/All/) > -1 ? '' : res.data.reportName
           })
+          dispatch('initPeople')
         }, 700)
       }
     },
@@ -959,6 +981,23 @@ export default {
           }
         }
       }
+    },
+    // 人员数据初始化
+    initPeople({ commit, state }) {
+      if (state.timeout !== null) {
+        clearTimeout(state.timeout)
+      }
+      state.timeout = setTimeout(async() => {
+        const res = await getListPerson({ memberIDAPs: state.peopleLists })
+        if (res.code === 200 && res.data && res.data.length) {
+          const userNames = {}
+          res.data.forEach(elm => {
+            const { idap, name } = elm
+            userNames[idap] = name
+          })
+          state.userNames = userNames
+        }
+      }, 400)
     }
   }
 }

+ 52 - 19
src/store/modules/monthlyReport/edit/utils.js

@@ -5,6 +5,7 @@ import _ from 'lodash'
 // 月报标签页基础数据过滤设置
 export function setReportData(obj, line = 6) {
   const domKeys = []
+  let peopleLists = []
   const newObj = { ...obj }
   const setDomInfo = (arr) => {
     let index = -1
@@ -26,9 +27,14 @@ export function setReportData(obj, line = 6) {
           item.domIndexKey = itemIndex
           item.domKey = uuid10(4)
           domKeys.indexOf(item.domKey) < 0 && domKeys.push(elm.domKey)
-          if (item.type.search(/Table|TableAndRichText/) > -1) {
+          if (item.type === 'ReadOnlyTable') {
             setTableHeader(item.tableHeaders)
-            item.tableRows = arrToObj(item.tableRows, item.tableHeaders)
+            item.tableRows = readOnlyTableArrToObj(item.tableRows, item.tableHeaders)
+          } else if (item.type.search(/Table|TableAndRichText/) > -1) {
+            setTableHeader(item.tableHeaders)
+            const { newObj, peopleList } = arrToObj(item.tableRows, item.tableHeaders)
+            item.tableRows = newObj
+            peopleLists = Array.from(new Set([...peopleLists, ...peopleList]))
           }
         })
       }
@@ -39,10 +45,7 @@ export function setReportData(obj, line = 6) {
   }
   if (newObj && newObj.children && newObj.children.length) {
     setDomInfo(newObj.children)
-    // newObj.children.forEach((elm) => {
-    //
-    // })
-    return { newObj, domKeys }
+    return { newObj, domKeys, peopleLists }
   }
   return {}
 }
@@ -79,7 +82,9 @@ export function reportDataBack(obj) {
       const { content, children } = elm
       if (content && content.length) {
         content.forEach((item) => {
-          if (item.type.search(/Table|TableAndRichText/) > -1) {
+          if (item.type === 'ReadOnlyTable') {
+            item.tableRows = readOnlyTableObjToArr(item.tableRows, item.tableHeaders)
+          } else if (item.type.search(/Table|TableAndRichText/) > -1) {
             item.tableRows = objToArr(item.tableRows, item.tableHeaders)
           }
         })
@@ -91,13 +96,6 @@ export function reportDataBack(obj) {
   }
   if (newObj && newObj.children && newObj.children.length) {
     setOldData(newObj.children)
-    // newObj.children.forEach((elm) => {
-    //   elm.content.forEach((item) => {
-    //     if (item.type === 'table') {
-    //       item.tableRows = objToArr(item.tableRows, item.tableHeaders)
-    //     }
-    //   })
-    // })
     return newObj
   }
   return []
@@ -109,13 +107,30 @@ export function setTableHeader(tableHeaders) {
   })
 }
 
+// 月报:表格数据转elm组件数据
+export function readOnlyTableArrToObj(arr, headerList) {
+  const newObj = []
+  const newArr = [...arr]
+  newArr.forEach((elm) => {
+    const obj = {}
+    headerList.forEach((helm, index) => {
+      const { headerKey } = helm
+      const item = elm.tableItems[index]
+      if (item) {
+        obj[headerKey] = item
+      }
+    })
+    newObj.push(obj)
+  })
+  return newObj
+}
 // 月报:表格数据转elm组件数据
 export function arrToObj(arr, headerList) {
   const newObj = []
+  let peopleList = []
   const newArr = [...arr]
   newArr.forEach((elm) => {
     const obj = {}
-    // elm.tableItems && elm.tableItems.length && elm.tableItems.forEach((item, index) => {
     headerList.forEach((helm, index) => {
       const { headerKey, displayType, name, itemInfo, selectType } = helm
       const item = elm.tableItems[index]
@@ -127,6 +142,8 @@ export function arrToObj(arr, headerList) {
           }
           if (selectType && selectType === 'MultiplePeople') {
             obj[headerKey] = strToArr(obj[headerKey])
+            peopleList = Array.from(new Set([...peopleList, ...obj[headerKey]]))
+            console.log({ peopleList })
           }
         }
         if (name === '问题') {
@@ -142,7 +159,7 @@ export function arrToObj(arr, headerList) {
     obj.operationTargetShow = false
     newObj.push(obj)
   })
-  return newObj
+  return { newObj, peopleList }
 }
 export function analyticFeedbackToObj(obj) {
   const newObj = _.cloneDeep(obj)
@@ -158,6 +175,25 @@ export function analyticFeedbackToObj(obj) {
   return newObj
 }
 
+// 月报:elm组件数据转表格数据
+export function readOnlyTableObjToArr(obj, tableHeaders) {
+  const newObj = [...obj]
+  const newArr = []
+  newObj.forEach((elm) => {
+    const elms = {}
+    tableHeaders.forEach((item, index) => {
+      let param = {}
+      console.log(192)
+      param = elm[item.headerKey]
+      if (!elms.tableItems) {
+        elms.tableItems = []
+      }
+      elms.tableItems.push(param)
+    })
+    newArr.push(elms)
+  })
+  return newArr
+}
 // 月报:elm组件数据转表格数据
 export function objToArr(obj, tableHeaders) {
   const newObj = [...obj]
@@ -176,12 +212,9 @@ export function objToArr(obj, tableHeaders) {
         }
         if (param.value) {
           if (item.displayType && item.displayType.search(/Cascader|CascaderSingle/) > -1) {
-            // param.value = arrToStr(param.value)
             param.value = JSON.stringify(param.value)
           }
           if (item.selectType && item.selectType === 'MultiplePeople') {
-            // param.value = JSON.stringify(param.value)
-            // param.value = arrToStr(param.value)
             param.value = JSON.stringify(param.value)
           }
         }

+ 60 - 21
src/views/monthlyReport/childrenPage/editReport/components/MultiplePeopleInfo.vue

@@ -25,6 +25,7 @@ export default {
   data() {
     return {
       timeOut: false,
+      isInit: true,
       userName: []
     }
   },
@@ -35,37 +36,75 @@ export default {
   },
   watch: {
     teamData() {
-      if (this.teamData && this.teamData.length) {
-        this.init()
-      }
+      console.log(39)
+      // this.init(this.isInit)
+    },
+    userNames(newVal, oldVal) {
+      this.initPeople()
     }
   },
   mounted() {
-    if (this.teamData && this.teamData.length) {
-      this.init()
-    }
+    console.log(58)
+    // setTimeout(() => {
+    // this.init(true)
+    // }, 700)
+    this.initPeople()
   },
   methods: {
-    // 根据传入类型判断数据
-    init() {
-      this.userName = []
-      let index = typeof this.teamData === 'string' ? 'a9527' : 0
-      const getInfo = () => {
-        this.getMember(
-          index !== 'a9527' ? this.teamData[index] : this.teamData,
-          () => {
-            if (index !== 'a9527' && !this.timeOut) {
-              index++
-              getInfo()
+    //
+    initPeople() {
+      if (this.teamData && this.teamData.length && this.userNames) {
+        if (typeof this.teamData === 'string') {
+          this.userName = [this.userNames[this.teamData]]
+          if (!this.userName[0]) {
+            this.$store.commit('monthlyReportEdit/SET_PEOPLELISTS', [this.teamData])
+            this.$store.dispatch('monthlyReportEdit/initPeople')
+          }
+        } else {
+          this.userName = []
+          const noName = []
+          this.teamData.length && this.teamData.forEach(value => {
+            const name = this.userNames[value]
+            if (name) {
+              this.userName.push(this.userNames[value])
+            } else {
+              noName.push(value)
             }
+          })
+          // noName = Array.from(new Set([...noName]))
+          this.userName = Array.from(new Set([...this.userName]))
+          if (noName.length) {
+            this.$store.commit('monthlyReportEdit/SET_PEOPLELISTS', noName)
+            this.$store.dispatch('monthlyReportEdit/initPeople')
           }
-        )
+        }
+        console.log(this.teamData, 65)
+        this.isInit = false
+      }
+    },
+    // 根据传入类型判断数据
+    init(isInit) {
+      if (this.teamData && this.teamData.length) {
+        this.userName = []
+        let index = typeof this.teamData === 'string' ? 'a9527' : 0
+        const getInfo = () => {
+          this.getMember(
+            index !== 'a9527' ? this.teamData[index] : this.teamData,
+            () => {
+              if (index !== 'a9527' && !this.timeOut) {
+                index++
+                getInfo()
+              }
+            },
+            isInit
+          )
+        }
+        getInfo()
       }
-      getInfo()
     },
-    getMember(query, cb) {
+    getMember(query, cb, isInit = false) {
       if (!query) return
-      if (this.userNames[query]) {
+      if (this.userNames[query] && isInit) {
         this.userName.push(this.userNames[query])
         cb()
       } else {

+ 19 - 5
src/views/monthlyReport/childrenPage/editReport/components/ReadOnlyTable.vue

@@ -19,17 +19,17 @@
         <el-table-column
           v-for="(item, itemIndex) in setColumns(columns)"
           :key="item.headerKey"
-          :data-index="index"
+          :data-index="itemIndex"
           :prop="item.headerKey"
           :align="item.align"
           :label="item.name"
           :type="item.type"
           :min-width="setMinWidth(item)"
-          :fixed="isFixed(item, index, columns)"
+          :fixed="isFixed(item, itemIndex, columns)"
         >
           <template slot-scope="scope">
             <div class="edit-wrapper">
-              <span class="edit-cell" @click.stop="query(scope.row, itemIndex)" v-html="scope.row[item.headerKey]" />
+              <span class="edit-cell" @click.stop="query(scope, itemIndex)" v-html="scope.row[item.headerKey].value" />
             </div>
           </template>
         </el-table-column>
@@ -99,6 +99,17 @@ export default {
       bugHour: ['全部修复', '24小时内修复', '修复时长超过24小时']
     }
   },
+  computed: {
+    tabsActive() {
+      return this.$store.state.monthlyReportEdit.tabsActive
+    },
+    pageType() {
+      return this.$store.state.monthlyReportEdit.pageType
+    },
+    pageDate() {
+      return this.$store.state.monthlyReportEdit.pageDate
+    }
+  },
   methods: {
     // 添加插入
     setColumns(columns) {
@@ -188,7 +199,10 @@ export default {
       return false
     },
     // 半浮层逻辑
-    query(data, index) {
+    query({ row, column }, index) {
+      // console.log(row, column.property, itemIndex)
+      const data = row[column.property]
+      // return
       if (index <= 2) {
         const yaxis = this.setList(data, index)
         this.requireList = { toType: '缺陷', xaxis: this.bugPriority, title: '新增缺陷', yaxis: yaxis, dataIndex: index }
@@ -250,7 +264,7 @@ export default {
     setList(data, index) {
       if (data.reportBugs[0]) {
         const [q, w, e, r, t] = [[], [], [], [], []]
-        data.reportBugs.map(item => {
+        data.reportBugs.forEach(item => {
           q.push(item.id) // 全部
           if (item.priority === 0) { r.push(item.id) } // P0
           if (item.priority === 1) { t.push(item.id) } // P1

+ 1 - 1
src/views/monthlyReport/childrenPage/editReport/components/SubTitle.vue

@@ -54,7 +54,7 @@ export default {
     setList(data, index) {
       if (data.reportBugs[0]) {
         const [q, w, e, r, t] = [[], [], [], [], []]
-        data.reportBugs.map(item => {
+        data.reportBugs.forEach(item => {
           q.push(item.id) // 全部
           if (item.priority === 0) { r.push(item.id) } // P0
           if (item.priority === 1) { t.push(item.id) } // P1