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
<template>
  <div>
    <a-table :columns="columns" :data-source="dataSource" bordered :pagination="false" :size="size" rowKey="fileId"
             :customRow="customRow" :scroll="{y:189}">
      <template slot="fileName" slot-scope="text,record,index">
      <span>
        {{ text }}.{{ record.fileSuffix }}
        <span v-if="record.publishFlag">[当前版本]</span>
      </span>
      </template>
    </a-table>
 
    <SelectFileCompareModal :dataSource="dataSource" :setCurrentVersionColor="setCurrentVersionColor"
                            ref="selectFileCompareModalRef"/>
  </div>
</template>
 
<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@/api/manage'
import dncApi from '@/api/dnc'
import SelectFileCompareModal from './SelectFileCompareModal'
 
export default {
  name: 'DocumentVersionTableList',
  mixins: [JeecgListMixin],
  components: { SelectFileCompareModal },
  props: {
    currentDocumentInfo: {
      type: Object
    },
    size: {
      type: String
    }
  },
  data() {
    return {
      disableMixinCreated: true,
      queryParams: {},
      columns: [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          width: 65,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        { title: '文件名称', dataIndex: 'fileName', align: 'center', scopedSlots: { customRender: 'fileName' },width: 500},
        { title: '版本号', dataIndex: 'docVersion', align: 'center' ,width: 200},
        { title: '文件大小', dataIndex: 'fileSize', align: 'center' ,width: 150}
      ],
      url: {
        list: '/nc/file/find/list'
      }
    }
  },
  created() {
    this.$bus.$on('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod)
  },
  beforeDestroy() {
    this.$bus.$off('tableMenuItemMethodTrigger', this.triggerCorrespondingMethod)
  },
  methods: {
    // 加载列表数据
    loadData() {
      this.dataSource = []
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      var params = this.getQueryParams()//查询条件
      params.docId = this.currentDocumentInfo.docId
      if (!params) {
        return false
      }
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) this.dataSource = res.list
          else {
            that.$notification.error({
              message: '消息',
              description: res.message
            })
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
 
    /**
     * 指定当前文档为当前版本
     * @param fileId 文件Id
     */
    handleFileAssign({ fileId, publishFlag }) {
      const that = this
      console.log('publishFlag', publishFlag)
      // 如果当前指定版本的版本号与当前版本的版本号一致则不发起请求
      if (publishFlag) {
        that.$notification.info({
          message: '消息',
          description: '当前文档版本即为当前文件'
        })
        return
      }
      dncApi.appointCurrentDocumentVersionApi(fileId)
        .then(res => {
          if (res.success) {
            that.$notification.success({
              message: '消息',
              description: res.message
            })
            that.loadData()
            that.$emit('releaseFilePreviewApi')
          } else {
            that.$notification.error({
              message: '消息',
              description: res.message
            })
          }
        })
        .catch(err => {
          that.$notification.error({
            message: '消息',
            description: err.message
          })
        })
    },
 
    /**
     * 比对两个版本的文档内容
     * @param _
     * @param modalTitle 弹窗标题
     */
    handleFileAddRelative(_, modalTitle) {
      if (!this.$refs.selectFileCompareModalRef) return
      this.$refs.selectFileCompareModalRef.visible = true
      this.$refs.selectFileCompareModalRef.title = modalTitle
    },
 
    /**
     * 定制表格行样式及功能
     * @param record 表格行信息
     * @returns {{style: {color: (string)}, on: {contextmenu: *}}} 样式及功能
     */
    customRow(record) {
      return {
        style: {
          color: this.setCurrentVersionColor(record.publishFlag)
        },
        on: {
          contextmenu: event => {
            event.preventDefault()
            this.$emit('handleTableContextMenuOpen', Object.assign({ param: 'file' }, record))
          }
        }
      }
    },
 
    /**
     * 设置表格中为当前版本的文件表格行颜色标识
     * @param publishFlag 是否为当前版本
     * @returns {string} 颜色标识
     */
    setCurrentVersionColor(publishFlag) {
      return publishFlag ? '#DB9538' : ''
    },
 
    triggerCorrespondingMethod({ methodName, modalTitle, tableRowInfo }) {
      if (this[methodName]) this[methodName](tableRowInfo, modalTitle)
    }
  }
}
</script>