archives.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <com-dialog
  3. title="火调档案管理"
  4. enterText="上传附件"
  5. :hideFloor="user.info.departmentId != organizerDeptId"
  6. :show="show"
  7. @submit="oper.readyInsert"
  8. @update:show="val => $emit('update:show', val)"
  9. >
  10. <div class="body-layer" style="padding: 0">
  11. <el-table
  12. ref="multipleTable"
  13. :data="tableData"
  14. tooltip-effect="dark"
  15. style="width: 100%;min-height:540px;max-height:540px"
  16. :span-method="arraySpanMethod"
  17. >
  18. <el-table-column label="附件标题" v-slot:default="{row}">
  19. <span :class="{title: row._title}">{{row._title ? row._title : row.fileName}}</span>
  20. </el-table-column>
  21. <el-table-column label="创建人" prop="creatorName"></el-table-column>
  22. <el-table-column label="创建日期" prop="updateTime" width="200" v-slot:default="{row}">
  23. {{row.updateTime ? row.updateTime.toString() : ''}}
  24. </el-table-column>
  25. <el-table-column label="操作" v-slot:default="{ row }" width="150">
  26. <a class="oper-span" :href="row.fileOssUrl" target="_blank">查看</a>
  27. <span class="oper-span" @click="downloadFile(row.fileOssUrl, row.fileName)">下载</span>
  28. <span class="oper-span"
  29. :class="{disable: user.info.departmentId != organizerDeptId}"
  30. @click="user.info.departmentId == organizerDeptId && deleteItem(row)"
  31. style="color: var(--primaryColor)">
  32. 删除
  33. </span>
  34. </el-table-column>
  35. </el-table>
  36. </div>
  37. </com-dialog>
  38. <com-dialog
  39. title="上传附件"
  40. v-model:show="oper.state.show"
  41. width="540"
  42. enterText="确 定"
  43. @submit="submit"
  44. >
  45. <el-form ref="form" :model="form" label-width="90px" class="camera-from dispatch-file-from">
  46. <el-form-item label="附件标题:" class="mandatory">
  47. <el-input v-model="oper.state.fileName" class="arch-name" placeholder="请输入最多不能超过50字" maxlength="50" show-word-limit></el-input>
  48. </el-form-item>
  49. <el-form-item label="附件类型:" class="mandatory">
  50. <el-select v-model="oper.state.attachmentType" placeholder="请选择">
  51. <el-option
  52. v-for="item in types"
  53. :key="item.name"
  54. :label="item.name"
  55. :value="item.name">
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item label="附件:" class="mandatory">
  60. <el-upload
  61. class="upload-demo"
  62. :http-request="uploadFile"
  63. :multiple="false"
  64. :limit="1"
  65. :before-upload="beforeUpload"
  66. :before-remove="beforeRemove"
  67. :file-list="oper.state.fileList">
  68. <el-button size="medium" type="primary" :disabled="!!oper.state.fileOssUrl" @click="ev => oper.state.fileOssUrl && ev.stopPropagation()"><i class="el-icon-upload2 el-icon--left"></i>上传</el-button>
  69. <template v-slot:tip>
  70. <div class="el-upload__tip">注:可上传100M以内的pdf、jpg、word文件</div>
  71. </template>
  72. </el-upload>
  73. </el-form-item>
  74. </el-form>
  75. </com-dialog>
  76. </template>
  77. <script>
  78. import getTableState from "@/state/tableRef";
  79. import {
  80. getAttachList,
  81. unbindCamera,
  82. insertAttach,
  83. uploadAttachFile,
  84. uploadAttachImage,
  85. deleteAttachFile
  86. } from '@/request/config'
  87. import comDialog from "@/components/dialog";
  88. import user from '@/state/user'
  89. import axios from 'axios';
  90. import { watch } from 'vue';
  91. import { downloadFile } from '@/util'
  92. const fileTypes = ['pdf', 'word']
  93. const imgTypes = ['jpeg', 'jpg']
  94. import { types } from '@/constant'
  95. export default {
  96. name: 'archives',
  97. props: ['show', 'data', 'organizerDeptId'],
  98. setup(props) {
  99. const state = getTableState({
  100. getUrl: getAttachList,
  101. insertUrl: insertAttach,
  102. delUrl: deleteAttachFile,
  103. delAttr: {ids: 'ids'},
  104. pagAttr: {list: ''},
  105. searchAttr: {pageSize: 12, projectId: props.data},
  106. operAttr: {
  107. attachmentType: '',
  108. fileOssUrl: '',
  109. fileName: '',
  110. projectId: '',
  111. type: '0'
  112. },
  113. });
  114. watch(props, () => {
  115. if (props.data === state.search.value.state.projectId) return
  116. state.search.value.state.projectId = props.data
  117. state.dataList.value.refer()
  118. })
  119. return { ...state, types, user };
  120. },
  121. methods: {
  122. async deleteItem(row) {
  123. await this.dataList.delete({ids: row.id})
  124. this.$emit('referList')
  125. },
  126. async unbindCamrea(data) {
  127. if (data.departmentId && (await this.$confirm('解绑相机,该相机拍摄的场景也将一并解绑(场景在云端存储,不会删除)确定要解绑吗?', '提示'))) {
  128. await axios.post(unbindCamera, data)
  129. data.departmentName = data.departmentId = null
  130. }
  131. this.dataList.refer()
  132. },
  133. arraySpanMethod({ row, columnIndex }) {
  134. if (row._title ) {
  135. return columnIndex === 0 ? [1, 4] : [0, 0]
  136. }
  137. },
  138. async uploadFile(data) {
  139. let url;
  140. if (imgTypes.some(type => ~data.file.type.indexOf(type))) {
  141. url = uploadAttachImage
  142. this.oper.state.type = 1
  143. } else {
  144. url = uploadAttachFile
  145. this.oper.state.type = 2
  146. }
  147. try {
  148. let res = await axios.post(url, {file: data.file})
  149. this.oper.state.fileOssUrl = res.data.ossUrl
  150. data.onSuccess()
  151. } catch {
  152. data.onError()
  153. }
  154. },
  155. beforeUpload(file) {
  156. let successTypes = [...imgTypes, ...fileTypes]
  157. let maxSize = 100 * 1024 * 1024
  158. if (!successTypes.some(type => ~file.type.indexOf(type))) {
  159. this.$message.error(`请上传${successTypes.join('、')}等格式的文件`, '提示')
  160. return false
  161. } else if (file.size > maxSize) {
  162. this.$message.error('请上传100M以内的文件', '提示')
  163. return false
  164. } else {
  165. return true
  166. }
  167. },
  168. beforeRemove() {
  169. this.oper.state.fileOssUrl = void 0
  170. },
  171. submit() {
  172. this.oper.state.projectId = this.search.state.projectId
  173. if (!this.oper.state.attachmentType) {
  174. return this.$message.error('附件类型不能为空!', '提示')
  175. } else if (!this.oper.state.fileOssUrl || !this.oper.state.fileOssUrl.trim()) {
  176. return this.$message.error('请上传附件!', '提示')
  177. } else if (!this.oper.state.fileName || !this.oper.state.fileName.trim()) {
  178. return this.$message.error('附件标题不能为空!', '提示')
  179. }
  180. this.oper.state.id ? this.oper.update() : this.oper.insert()
  181. this.$emit('referList')
  182. },
  183. downloadFile
  184. },
  185. computed: {
  186. tableData() {
  187. let dataList = this.dataList.state || []
  188. let data = this.types.reduce((t, c) =>
  189. t.concat(
  190. {_title: c.name},
  191. dataList.filter(item => c.name === item.attachmentType)
  192. )
  193. , [])
  194. data = data.concat(dataList.filter(item => !data.includes(item)))
  195. return data
  196. }
  197. },
  198. components: {
  199. "com-dialog": comDialog,
  200. }
  201. };
  202. </script>
  203. <style lang="scss" scoped>
  204. .table-ctrl-right {
  205. .search-scene {
  206. margin: 0 20px 0 26px;
  207. }
  208. i {
  209. margin-left: 20px;
  210. font-size: 1.7rem;
  211. vertical-align: middle;
  212. cursor: pointer;
  213. &.active {
  214. color: var(--primaryColor);
  215. }
  216. }
  217. }
  218. .title {
  219. font-weight: bold;
  220. color: #26559B;
  221. line-height: 19px;
  222. font-size: 14px;
  223. }
  224. </style>
  225. <style>
  226. .upload-demo .el-upload {
  227. line-height: initial;
  228. }
  229. .arch-name .el-input__inner{
  230. padding-right: 50px;
  231. }
  232. </style>