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.

190 lines
6.2KB

  1. <template>
  2. <div class="app-container" style="padding: 8px;">
  3. <!--表单组件-->
  4. <eForm ref="form" />
  5. <!-- 工具栏 -->
  6. <div class="head-container">
  7. <div v-if="crud.props.searchToggle">
  8. <!-- 搜索 -->
  9. <el-input v-model="query.key" clearable size="small" placeholder="输入文件名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
  10. <date-range-picker v-model="query.createTime" class="date-item" />
  11. <rrOperation />
  12. </div>
  13. <crudOperation :permission="permission">
  14. <template slot="left">
  15. <!-- 上传 -->
  16. <el-button class="filter-item" size="mini" type="primary" icon="el-icon-upload" @click="dialog = true">上传</el-button>
  17. <!-- 同步 -->
  18. <el-button :icon="icon" class="filter-item" size="mini" type="warning" @click="synchronize">同步</el-button>
  19. <!-- 配置 -->
  20. <el-button
  21. class="filter-item"
  22. size="mini"
  23. type="success"
  24. icon="el-icon-s-tools"
  25. @click="doConfig"
  26. >配置</el-button>
  27. </template>
  28. </crudOperation>
  29. <!-- 文件上传 -->
  30. <el-dialog :visible.sync="dialog" :close-on-click-modal="false" append-to-body width="500px" @close="doSubmit">
  31. <el-upload
  32. :before-remove="handleBeforeRemove"
  33. :on-success="handleSuccess"
  34. :on-error="handleError"
  35. :file-list="fileList"
  36. :headers="headers"
  37. :action="qiNiuUploadApi"
  38. class="upload-demo"
  39. multiple
  40. >
  41. <el-button size="small" type="primary">点击上传</el-button>
  42. <div slot="tip" style="display: block;" class="el-upload__tip">请勿上传违法文件,且文件不超过15M</div>
  43. </el-upload>
  44. <div slot="footer" class="dialog-footer">
  45. <el-button type="primary" @click="doSubmit">确认</el-button>
  46. </div>
  47. </el-dialog>
  48. <!--表格渲染-->
  49. <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
  50. <el-table-column type="selection" width="55" />
  51. <el-table-column prop="name" :show-overflow-tooltip="true" label="文件名">
  52. <template slot-scope="scope">
  53. <a href="JavaScript:" class="el-link el-link--primary" target="_blank" type="primary" @click="download(scope.row.id)">{{ scope.row.key }}</a>
  54. </template>
  55. </el-table-column>
  56. <el-table-column :show-overflow-tooltip="true" prop="suffix" label="文件类型" @selection-change="crud.selectionChangeHandler" />
  57. <el-table-column prop="bucket" label="空间名称" />
  58. <el-table-column prop="size" label="文件大小" />
  59. <el-table-column prop="type" label="空间类型" />
  60. <el-table-column prop="updateTime" label="创建日期" />
  61. </el-table>
  62. <!--分页组件-->
  63. <pagination />
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import crudQiNiu from '@/api/tools/qiniu'
  69. import { mapGetters } from 'vuex'
  70. import { getToken } from '@/utils/auth'
  71. import eForm from './form'
  72. import CRUD, { presenter, header, crud } from '@crud/crud'
  73. import rrOperation from '@crud/RR.operation'
  74. import crudOperation from '@crud/CRUD.operation'
  75. import pagination from '@crud/Pagination'
  76. import DateRangePicker from '@/components/DateRangePicker'
  77. export default {
  78. components: { eForm, pagination, crudOperation, rrOperation, DateRangePicker },
  79. cruds() {
  80. return CRUD({ title: '七牛云文件', url: 'api/qiNiuContent', crudMethod: { ...crudQiNiu }})
  81. },
  82. mixins: [presenter(), header(), crud()],
  83. data() {
  84. return {
  85. permission: {
  86. del: ['admin', 'storage:del']
  87. },
  88. title: '文件', dialog: false,
  89. icon: 'el-icon-refresh',
  90. url: '', headers: { 'Authorization': getToken() },
  91. dialogImageUrl: '', dialogVisible: false, fileList: [], files: [], newWin: null
  92. }
  93. },
  94. computed: {
  95. ...mapGetters([
  96. 'qiNiuUploadApi'
  97. ])
  98. },
  99. watch: {
  100. url(newVal, oldVal) {
  101. if (newVal && this.newWin) {
  102. this.newWin.sessionStorage.clear()
  103. this.newWin.location.href = newVal
  104. // 重定向后把url和newWin重置
  105. this.url = ''
  106. this.newWin = null
  107. }
  108. }
  109. },
  110. created() {
  111. this.crud.optShow.add = false
  112. this.crud.optShow.edit = false
  113. },
  114. methods: {
  115. // 七牛云配置
  116. doConfig() {
  117. const _this = this.$refs.form
  118. _this.init()
  119. _this.dialog = true
  120. },
  121. handleSuccess(response, file, fileList) {
  122. const uid = file.uid
  123. const id = response.id
  124. this.files.push({ uid, id })
  125. },
  126. handleBeforeRemove(file, fileList) {
  127. for (let i = 0; i < this.files.length; i++) {
  128. if (this.files[i].uid === file.uid) {
  129. crudQiNiu.del([this.files[i].id]).then(res => {})
  130. return true
  131. }
  132. }
  133. },
  134. handlePictureCardPreview(file) {
  135. this.dialogImageUrl = file.url
  136. this.dialogVisible = true
  137. },
  138. // 刷新列表数据
  139. doSubmit() {
  140. this.fileList = []
  141. this.dialogVisible = false
  142. this.dialogImageUrl = ''
  143. this.dialog = false
  144. this.crud.toQuery()
  145. },
  146. // 监听上传失败
  147. handleError(e, file, fileList) {
  148. const msg = JSON.parse(e.message)
  149. this.crud.notify(msg.message, CRUD.NOTIFICATION_TYPE.ERROR)
  150. },
  151. // 下载文件
  152. download(id) {
  153. this.downloadLoading = true
  154. // 先打开一个空的新窗口,再请求
  155. this.newWin = window.open()
  156. crudQiNiu.download(id).then(res => {
  157. this.downloadLoading = false
  158. this.url = res.url
  159. }).catch(err => {
  160. this.downloadLoading = false
  161. console.log(err.response.data.message)
  162. })
  163. },
  164. // 同步数据
  165. synchronize() {
  166. this.icon = 'el-icon-loading'
  167. crudQiNiu.sync().then(res => {
  168. this.icon = 'el-icon-refresh'
  169. this.$message({
  170. showClose: true,
  171. message: '数据同步成功',
  172. type: 'success',
  173. duration: 1500
  174. })
  175. this.crud.toQuery()
  176. }).catch(err => {
  177. this.icon = 'el-icon-refresh'
  178. console.log(err.response.data.message)
  179. })
  180. }
  181. }
  182. }
  183. </script>
  184. <style scoped>
  185. </style>