Rap 原分销系统代码Web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

afb6ffeb685a350d260c1a810eaf7293bd22fd48.svn-base 6.2KB

5 月之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="app-container" style="padding: 8px;">
  3. <!--工具栏-->
  4. <div class="head-container">
  5. <div v-if="crud.props.searchToggle">
  6. <!-- 搜索 -->
  7. <el-input v-model="query.blurry" clearable size="small" placeholder="输入内容模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
  8. <date-range-picker v-model="query.createTime" class="date-item" />
  9. <rrOperation />
  10. </div>
  11. <crudOperation :permission="permission">
  12. <!-- 新增 -->
  13. <el-button
  14. slot="left"
  15. v-permission="['admin','storage:add']"
  16. class="filter-item"
  17. size="mini"
  18. type="primary"
  19. icon="el-icon-upload"
  20. @click="crud.toAdd"
  21. >上传
  22. </el-button>
  23. </crudOperation>
  24. </div>
  25. <!--表单组件-->
  26. <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.add ? '文件上传' : '编辑文件'" width="500px">
  27. <el-form ref="form" :model="form" size="small" label-width="80px">
  28. <el-form-item label="文件名">
  29. <el-input v-model="form.name" style="width: 370px;" />
  30. </el-form-item>
  31. <!-- 上传文件 -->
  32. <el-form-item v-if="crud.status.add" label="上传">
  33. <el-upload
  34. ref="upload"
  35. :limit="1"
  36. :before-upload="beforeUpload"
  37. :auto-upload="false"
  38. :headers="headers"
  39. :on-success="handleSuccess"
  40. :on-error="handleError"
  41. :action="fileUploadApi + '?name=' + form.name"
  42. >
  43. <div class="eladmin-upload"><i class="el-icon-upload" /> 添加文件</div>
  44. <div slot="tip" class="el-upload__tip">可上传任意格式文件,且不超过100M</div>
  45. </el-upload>
  46. </el-form-item>
  47. </el-form>
  48. <div slot="footer" class="dialog-footer">
  49. <el-button type="text" @click="crud.cancelCU">取消</el-button>
  50. <el-button v-if="crud.status.add" :loading="loading" type="primary" @click="upload">确认</el-button>
  51. <el-button v-else :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
  52. </div>
  53. </el-dialog>
  54. <!--表格渲染-->
  55. <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
  56. <el-table-column type="selection" width="55" />
  57. <el-table-column prop="name" label="文件名">
  58. <template slot-scope="scope">
  59. <el-popover
  60. :content="'file/' + scope.row.type + '/' + scope.row.realName"
  61. placement="top-start"
  62. title="路径"
  63. width="200"
  64. trigger="hover"
  65. >
  66. <a
  67. slot="reference"
  68. :href="baseApi + '/file/' + scope.row.type + '/' + scope.row.realName"
  69. class="el-link--primary"
  70. style="word-break:keep-all;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color: #1890ff;font-size: 13px;"
  71. target="_blank"
  72. >
  73. {{ scope.row.name }}
  74. </a>
  75. </el-popover>
  76. </template>
  77. </el-table-column>
  78. <el-table-column prop="path" label="预览图">
  79. <template slot-scope="{row}">
  80. <el-image
  81. :src=" baseApi + '/file/' + row.type + '/' + row.realName"
  82. :preview-src-list="[baseApi + '/file/' + row.type + '/' + row.realName]"
  83. fit="contain"
  84. lazy
  85. class="el-avatar"
  86. >
  87. <div slot="error">
  88. <i class="el-icon-document" />
  89. </div>
  90. </el-image>
  91. </template>
  92. </el-table-column>
  93. <el-table-column prop="suffix" label="文件类型" />
  94. <el-table-column prop="type" label="类别" />
  95. <el-table-column prop="size" label="大小" />
  96. <el-table-column prop="operate" label="操作人" />
  97. <el-table-column prop="createTime" label="创建日期" />
  98. </el-table>
  99. <!--分页组件-->
  100. <pagination />
  101. </div>
  102. </template>
  103. <script>
  104. import { mapGetters } from 'vuex'
  105. import { getToken } from '@/utils/auth'
  106. import crudFile from '@/api/tools/localStorage'
  107. import CRUD, { presenter, header, form, crud } from '@crud/crud'
  108. import rrOperation from '@crud/RR.operation'
  109. import crudOperation from '@crud/CRUD.operation'
  110. import pagination from '@crud/Pagination'
  111. import DateRangePicker from '@/components/DateRangePicker'
  112. const defaultForm = { id: null, name: '' }
  113. export default {
  114. components: { pagination, crudOperation, rrOperation, DateRangePicker },
  115. cruds() {
  116. return CRUD({ title: '文件', url: 'api/localStorage', crudMethod: { ...crudFile }})
  117. },
  118. mixins: [presenter(), header(), form(defaultForm), crud()],
  119. data() {
  120. return {
  121. delAllLoading: false,
  122. loading: false,
  123. headers: { 'Authorization': getToken() },
  124. permission: {
  125. edit: ['admin', 'storage:edit'],
  126. del: ['admin', 'storage:del']
  127. }
  128. }
  129. },
  130. computed: {
  131. ...mapGetters([
  132. 'baseApi',
  133. 'fileUploadApi'
  134. ])
  135. },
  136. created() {
  137. this.crud.optShow.add = false
  138. },
  139. methods: {
  140. // 上传文件
  141. upload() {
  142. this.$refs.upload.submit()
  143. },
  144. beforeUpload(file) {
  145. let isLt2M = true
  146. isLt2M = file.size / 1024 / 1024 < 100
  147. if (!isLt2M) {
  148. this.loading = false
  149. this.$message.error('上传文件大小不能超过 100MB!')
  150. }
  151. this.form.name = file.name
  152. return isLt2M
  153. },
  154. handleSuccess(response, file, fileList) {
  155. this.crud.notify('上传成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
  156. this.$refs.upload.clearFiles()
  157. this.crud.status.add = CRUD.STATUS.NORMAL
  158. this.crud.resetForm()
  159. this.crud.toQuery()
  160. },
  161. // 监听上传失败
  162. handleError(e, file, fileList) {
  163. const msg = JSON.parse(e.message)
  164. this.$notify({
  165. title: msg.message,
  166. type: 'error',
  167. duration: 2500
  168. })
  169. this.loading = false
  170. }
  171. }
  172. }
  173. </script>
  174. <style scoped>
  175. ::v-deep .el-image__error, .el-image__placeholder{
  176. background: none;
  177. }
  178. ::v-deep .el-image-viewer__wrapper{
  179. top: 55px;
  180. }
  181. </style>