HomeColumn.vue 12.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
<template>
  <div ref="colItem" v-loading="loading" class="el-card is-hover-shadow">
    <el-row class="col-item__header">
      <el-col
        :span="20"
        class="title drag-handler"
        :class="[columnItem.showTitle != 0 ? 'header-title' : 'no-title']"
      >
        <span v-if="columnItem.showTitle != 0">{{ columnItem.name }}</span>
        <!-- <el-select
          v-if="columnItem.dropDown"
          v-model="columnItem.dropDownValue"
          placeholder="请选择"
        >
          <el-option
            v-for="item in columnItem.dropDownData"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select> -->
      </el-col>

      <el-col :span="4" class="btn-group">
        <!-- <el-button
          v-if="columnItem.colUrl"
          type="text"
          title="更多"
          @click="openMore(columnItem.colUrl)"
        >
          <i class="el-icon-more"></i>
        </el-button> -->

        <el-button type="text" title="刷新" @click="refresh(columnItem)">
          <i class="el-icon-refresh"></i>
        </el-button>

        <el-button type="text" title="移除" @click="deleteColumn">
          <i class="el-icon-close"></i>
        </el-button>
      </el-col>
    </el-row>

    <div class="col-item__content">
      <v-runtime-template
        v-if="!isChart && !isCustomDialog"
        :parent="this"
        :template="decodeBase64ToHtml(columnItem)"
      />

      <ht-chart v-if="isChart" :id="chartId" :chart-key="chartId" />
      <custom-dialog
        v-if="isCustomDialog"
        ref="customDialog"
        :key="customDialog.alias"
        :is-show-pagination="isShowPagination"
        :alias="customDialog.alias"
        :custom-dialog="customDialog"
      />
    </div>

    <leader-dialog ref="leaderDialog" />
  </div>
</template>

<script>
  /* eslint-disable vue/no-unused-components */
  import OftenFlow from './OftenFlow'
  import homeUserInfo from './HomeUserInfo'
  import HomeNewsList from './HomeNewsList'
  import HomeCarousel from './HomeCarousel'
  import VRuntimeTemplate from 'v-runtime-template'
  import LeaderDialog from '@/views/matter/components/LeaderDialog'
  import CustomDialog from '@/views/home/components/CustomDialog'
  import req from '@/utils/request'
  import { parseExp } from '@/utils/parse.js'
  import { getMyOftenFlow } from '@/api/flow'
  import { getCustomDataByAlias } from '@/api/form.js'
  import CustomQuery from '@/services/CustomQuery.js'
  // 新注册的组件
  import Personalnformation from '@/views/home/components/HomeComponent/Personalnformation.vue'
  import CommonFunctions from '@/views/home/components/HomeComponent/CommonFunctions.vue'
  import TaskPanel from '@/views/home/components/HomeComponent/TaskPanel.vue'
  import ProjectSummary from '@/views/home/components/HomeComponent/ProjectSummary.vue'
  import CompanyNews from '@/views/home/components/HomeComponent/CompanyNews.vue'
  import SupervisionFeedback from '@/views/home/components/HomeComponent/SupervisionFeedback.vue'
  import ApprovalStatus from '@/views/home/components/HomeComponent/ApprovalStatus.vue'
  import BusinessConsulting from '@/views/home/components/HomeComponent/BusinessConsulting.vue'

  export default {
    name: 'HomeColumn',
    components: {
      Personalnformation, //个人信息栏目
      CommonFunctions, //常用功能
      TaskPanel, //任务面板
      CompanyNews, //公司新闻
      ProjectSummary, //项目汇总
      SupervisionFeedback, //督办反馈
      ApprovalStatus, //审批状态
      BusinessConsulting, //业务咨询
      OftenFlow,
      homeUserInfo,
      HomeNewsList,
      HomeCarousel,
      LeaderDialog,
      VRuntimeTemplate,
      CustomDialog,
    },
    props: {
      columnItem: {
        type: Object,
        required: true,
        default: () => null,
      },
    },
    data() {
      return {
        data: {},
        isChart: false,
        chartId: '',
        loading: false,
        portal: window.context.portal,
        html: '<span>本栏目无模板</span>',
        oftenFlowList: [],
        pageBean: {
          page: 1,
          pageSize: 10,
          total: 0,
          showTotal: false,
        },
        hotent: require('@/assets/index_images/hotent.png'),
        wechat: require('@/assets/index_images/wechat.png'),
        isCustomDialog: false,
        customDialog: { alias: '' },
      }
    },
    computed: {
      isShowPagination() {
        return this.customDialog.needPage ? false : true
      },
    },
    watch: {
      columnItem: {
        handler(val) {
          if (val) {
            this._getMyOftenFlow()
            this.handleColumnData(val)
          }
        },
        immediate: true,
      },
    },
    methods: {
      openMore(url) {},
      handleOpenUrl(url, newWin) {},
      handleTodoListClick(item) {},
      handleCurrentChange(currentPage) {},
      TableRowStyle({ row, rowIndex }) {},
      deleteColumn() {
        this.$confirm('确认删除该栏目吗?', '提示', {
          type: 'warning',
        })
          .then(() => {
            this.$emit('delete-column', this.columnItem)
          })
          .catch(() => {})
      },
      handleRowClick(path) {
        this.$router.push(path)
      },
      handleTodoClick(row, key = '') {
        this.$refs.leaderDialog.handleJumpsTodoPage(row, {
          isGetApprovalBtn: true,
          key,
        })
      },
      _getMyOftenFlow() {
        if (this.columnItem.alias === 'vueOftenFlow') {
          getMyOftenFlow().then((data) => {
            if (data && data.rows) {
              this.oftenFlowList = data.rows
            }
          })
        }
      },
      decodeBase64ToHtml(column) {
        if (column.templateHtml) {
          return Base64.decode(column.templateHtml)
        }
        return this.html
      },
      refresh(column) {
        this.loading = true
        this.$store
          .dispatch('menu/getColumnByAlias', column.alias)
          .then((data) => {
            this.$emit('column-refresh', data)
            setTimeout(() => {
              this.loading = false
            }, 300)
          })
          .catch(() => {
            this.loading = false
          })
      },
      handleColumnData(column) {
        const { colType, dataMode, dataParam } = column
        if ([1, 4].includes(colType)) {
          const dataObj = JSON.parse(dataParam)
          if (dataObj && dataObj.chartType === 2) {
            this.isChart = true
            this.chartId = dataObj.id
          } else {
            // TODO:其他情况
          }
        } else {
          // 0:一般栏目 2:滚动栏目
          switch (dataMode) {
            case 1:
              //自定义对话框
              this.getCustomDialogData()
              break
            case 3:
              // RESTFUL 查询
              this.getDataToParse(column)
              break
            case 4:
              // TODO:数据报表
              break
            case 5:
              // 关联查询
              if (column && column.alias) {
                CustomQuery.load(column.alias).then((resp) => {
                  this.data = resp
                })
              }
              break
          }
        }
      },
      getDataToParse(column) {
        const { dataFrom, colType, needPage, dataParam, requestType } = column
        if (!dataFrom || colType === 1) {
          return
        }

        // POST 请求参数
        const queryParams = {}
        if (needPage === 1) {
          queryParams.pageBean = this.pageBean
        }

        // GET 请求参数
        let urlParam = ''

        if (dataParam) {
          const ctx = {}
          if (this.$store.state.user) {
            const { userId, username } = this.$store.state.user
            ctx.curUserId = userId
            ctx.curUserAccount = username
          }
          column.dataParam = parseExp(column.dataParam, ctx)
        }

        const dataParamParse = JSON.parse(
          typeof dataParam != 'undefined' && dataParam !== ''
            ? dataParam.replace(/\\\\/g, '\\')
            : '[]'
        )
        if (dataParamParse) {
          for (let i = 0; i < dataParamParse.length; i++) {
            let { name, value } = dataParamParse[i]
            if (requestType === 'POST') {
              try {
                value = JSON.parse(value)
              } catch (e) {}

              const queryValue =
                name === 'pageBean'
                  ? { ...value, page: this.pageBean.page }
                  : name === 'querys'
                  ? [...value]
                  : value
              queryParams[name] = queryValue
            } else {
              urlParam =
                i > 0 ? `${urlParam}&${name}=${value}` : `?${name}=${value}`
            }
          }
        }

        // 根据请求参数获取数据
        const requestUrl = this.getRequestUrl(dataFrom)
        if (requestType === 'POST') {
          req.post(requestUrl, queryParams).then(
            (res) => {
              this.data = { ...res }
              if (needPage === 1) {
                this.pageBean.page = this.data.page || 1
                this.pageBean.pageSize = this.data.pageSize || 10
                this.pageBean.total = this.data.total || 0
              }
            },
            (err) => {
              this.html = `<span style='color:red;'>${err}</span>`
            }
          )
        } else {
          req.get(requestUrl + urlParam).then(
            (res) => {
              this.data = { ...res }
            },
            (err) => {
              this.html = `<span style='color:red;'>${err}</span>`
            }
          )
        }
      },
      getRequestUrl(dataFrom) {
        const { uc, form, portal, bpmModel, bpmRunTime } = window.context
        const reqUrl = dataFrom
          .replace('${uc}', uc)
          .replace('${form}', form)
          .replace('${portal}', portal)
          .replace('${bpmModel}', bpmModel)
          .replace('${bpmRunTime}', bpmRunTime)
        return reqUrl
      },
      getCustomDialogData() {
        let this_ = this
        let dataFrom = JSON.parse(this.columnItem.dataFrom || '{}')
        if (!dataFrom.alias) {
          this_.loading = false
          this_.isCommon = true
          return
        }
        getCustomDataByAlias(dataFrom.alias).then((customDialog) => {
          //格式化对话框的显示字段、返回字段、条件字段、排序字段
          customDialog.displayfield = JSON.parse(customDialog.displayfield)
          for (let i = 0; i < customDialog.displayfield.length; i++) {
            customDialog.displayfield[i].field =
              customDialog.displayfield[i].field.toUpperCase()
          }
          customDialog.resultfield = JSON.parse(customDialog.resultfield)
          customDialog.sortfield = JSON.parse(customDialog.sortfield)
          customDialog.conditionfield = JSON.parse(customDialog.conditionfield)
          //列表
          if (customDialog.style == 0) {
            this_.customDialog = customDialog
            this_.isCustomDialog = true
            this_.loading = false
            setTimeout(() => {
              this_.$refs.customDialog.initData() //显示自定义对话框列表预览弹框
            })
          }
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  .col-item__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid $base-border-color;
    padding: 0 18px;
    .title {
      flex: 1;
      color: var(--themeColor);
      font-size: $base-font-size-big;
      padding: 16px 0;
      cursor: move;
    }
    .header-title {
      &::before {
        position: relative;
        top: 3px;
        display: inline-block;
        content: '';
        width: 4px;
        height: 19px;
        margin-right: 10px;
        background: var(--themeColor);
      }
      span {
        font-weight: 600;
        color: #000000;
      }
    }
    .no-title {
      padding: 28px 0;
    }
    .btn-group {
      padding: 5px 0;
      display: flex;
      justify-content: flex-end;
    }
    i {
      font-size: $base-font-size-default;
    }
  }
  .col-item__content {
    padding: 16px 18px;
  }

  // 个人信息栏目
  ::v-deep .grxxlm {
    .grxxlm-color {
      color: #919191;
    }
  }

  // 常用系统
  ::v-deep .cyxt {
    .cyxt-color {
      color: #919191;
    }
  }

  // 我的待办
  ::v-deep .my-todo {
    background: transparent;
  }
</style>