plm前端
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.

173 lines
4.7 KiB

2 years ago
  1. <template>
  2. <div class="mod-oss">
  3. <el-form :inline="true" :model="dataForm">
  4. <el-form-item>
  5. <el-button type="primary" @click="configHandle()">云存储配置</el-button>
  6. <el-button type="primary" @click="uploadHandle()">上传文件</el-button>
  7. <el-button type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
  8. </el-form-item>
  9. </el-form>
  10. <el-table
  11. :data="dataList"
  12. border
  13. v-loading="dataListLoading"
  14. @selection-change="selectionChangeHandle"
  15. style="width: 100%;">
  16. <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
  17. <el-table-column
  18. prop="url"
  19. header-align="center"
  20. align="center"
  21. label="URL地址">
  22. </el-table-column>
  23. <el-table-column
  24. prop="createDate"
  25. header-align="center"
  26. align="center"
  27. width="180"
  28. label="创建时间">
  29. </el-table-column>
  30. <el-table-column
  31. fixed="right"
  32. header-align="center"
  33. align="center"
  34. width="150"
  35. label="操作">
  36. <template slot-scope="scope">
  37. <a type="text" size="small" @click="deleteHandle(scope.row.id)">删除</a>
  38. <a @click="downloadFile(scope.row.fileName, scope.row.url)">下载</a>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <el-pagination
  43. @size-change="sizeChangeHandle"
  44. @current-change="currentChangeHandle"
  45. :current-page="pageIndex"
  46. :page-sizes="[20, 50, 100 , 200, 500]"
  47. :page-size="pageSize"
  48. :total="totalPage"
  49. layout="total, sizes, prev, pager, next, jumper">
  50. </el-pagination>
  51. <!-- 弹窗, 云存储配置 -->
  52. <config v-if="configVisible" ref="config"></config>
  53. <!-- 弹窗, 上传文件 -->
  54. <upload v-if="uploadVisible" ref="upload" @refreshDataList="getDataList"></upload>
  55. </div>
  56. </template>
  57. <script>
  58. import Config from './oss-config'
  59. import Upload from './oss-upload'
  60. export default {
  61. data() {
  62. return {
  63. dataForm: {},
  64. dataList: [],
  65. pageIndex: 1,
  66. pageSize: 20,
  67. totalPage: 0,
  68. dataListLoading: false,
  69. dataListSelections: [],
  70. configVisible: false,
  71. uploadVisible: false
  72. }
  73. },
  74. components: {
  75. Config,
  76. Upload
  77. },
  78. activated() {
  79. this.getDataList()
  80. },
  81. methods: {
  82. downloadFile(fileName, data) {
  83. if (!data) {
  84. return;
  85. }
  86. let url = window.URL.createObjectURL(new Blob([data]));
  87. let link = document.createElement('a');
  88. link.style.display = 'none';
  89. link.href = url;
  90. link.setAttribute('download', fileName);
  91. document.body.appendChild(link);
  92. link.click();
  93. },
  94. // 获取数据列表
  95. getDataList() {
  96. this.dataListLoading = true
  97. this.$http({
  98. url: this.$http.adornUrl('/sys/oss/list'),
  99. method: 'get',
  100. params: this.$http.adornParams({
  101. 'page': this.pageIndex,
  102. 'limit': this.pageSize
  103. })
  104. }).then(({data}) => {
  105. if (data && data.code === 0) {
  106. this.dataList = data.page.list
  107. this.totalPage = data.page.totalCount
  108. } else {
  109. this.dataList = []
  110. this.totalPage = 0
  111. }
  112. this.dataListLoading = false
  113. })
  114. },
  115. // 每页数
  116. sizeChangeHandle(val) {
  117. this.pageSize = val
  118. this.pageIndex = 1
  119. this.getDataList()
  120. },
  121. // 当前页
  122. currentChangeHandle(val) {
  123. this.pageIndex = val
  124. this.getDataList()
  125. },
  126. // 多选
  127. selectionChangeHandle(val) {
  128. this.dataListSelections = val
  129. },
  130. // 云存储配置
  131. configHandle() {
  132. this.configVisible = true
  133. this.$nextTick(() => {
  134. this.$refs.config.init()
  135. })
  136. },
  137. // 上传文件
  138. uploadHandle() {
  139. this.uploadVisible = true
  140. this.$nextTick(() => {
  141. this.$refs.upload.init()
  142. })
  143. },
  144. // 删除
  145. deleteHandle(id) {
  146. var ids = id ? [id] : this.dataListSelections.map(item => {
  147. return item.id
  148. })
  149. this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  150. confirmButtonText: '确定',
  151. cancelButtonText: '取消',
  152. type: 'warning'
  153. }).then(() => {
  154. this.$http({
  155. url: this.$http.adornUrl('/sys/oss/delete'),
  156. method: 'post',
  157. data: this.$http.adornData(ids, false)
  158. }).then(({data}) => {
  159. if (data && data.code === 0) {
  160. this.$message.success('操作成功')
  161. this.getDataList()
  162. } else {
  163. this.$message.error(data.msg)
  164. }
  165. })
  166. }).catch(() => {
  167. })
  168. }
  169. }
  170. }
  171. </script>