Index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div id="app-demo-file">
  3. <div class="one-block-1">
  4. <span>
  5. 上传文件到sm图床
  6. </span>
  7. </div>
  8. <div class="one-block-2">
  9. <!-- dev调试时,action参数:请填写你本地完整的api地址,如:http://localhost:7068/api/v1/example/uploadFile -->
  10. <a-upload-dragger
  11. name="file"
  12. :multiple="true"
  13. :action="action_url"
  14. @change="handleChange"
  15. >
  16. <p class="ant-upload-drag-icon">
  17. <a-icon type="inbox" />
  18. </p>
  19. <p class="ant-upload-text">
  20. Click or drag file to this area to upload
  21. </p>
  22. <p class="ant-upload-hint">
  23. Support for a single or bulk upload. Strictly prohibit from uploading company data or other
  24. band files
  25. </p>
  26. </a-upload-dragger>
  27. </div>
  28. <div class="one-block-2">
  29. <a-list v-if="image_info.length !== 0" size="small" bordered :data-source="image_info">
  30. <a-list-item slot="renderItem" slot-scope="item" style="text-align:left;">
  31. {{ item.id }}.&nbsp;{{ item.imageUrlText }}:&nbsp;
  32. <a :href="item.url" target="_blank">{{ item.url }}</a>
  33. </a-list-item>
  34. </a-list>
  35. </div>
  36. <div class="one-block-1">
  37. <span>
  38. 打开文件夹
  39. </span>
  40. </div>
  41. <div class="one-block-2">
  42. <a-list :grid="{ gutter: 16, column: 4 }" :data-source="file_list">
  43. <a-list-item slot="renderItem" slot-scope="item" @click="openDirectry(item.id)">
  44. <a-card :title="item.content">
  45. <a-button type="link">
  46. 打开
  47. </a-button>
  48. </a-card>
  49. </a-list-item>
  50. </a-list>
  51. </div>
  52. <div class="one-block-1">
  53. <span>
  54. 保存到目录
  55. </span>
  56. </div>
  57. <div class="one-block-2">
  58. <a-input addon-before="保存目录" v-model="dir_path" :value="dir_path" />
  59. <a-button @click="selectDir">修改目录</a-button>
  60. <!-- <a-card hoverable style="width: 100%">
  61. <template slot="actions" class="ant-card-actions">
  62. <a @click="selectDir">修改目录</a>
  63. </template>
  64. <a-card-meta v-model="dir_path" title="保存目录" :description="dir_path">
  65. </a-card-meta>
  66. </a-card> -->
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import { localApi } from '@/api/main'
  72. const fileList = [
  73. {
  74. content: '【下载】目录',
  75. id: 'download'
  76. },
  77. {
  78. content: '【图片】目录',
  79. id: 'picture'
  80. },
  81. {
  82. content: '【文档】目录',
  83. id: 'doc'
  84. },
  85. {
  86. content: '【音乐】目录',
  87. id: 'music'
  88. }
  89. ];
  90. export default {
  91. data() {
  92. return {
  93. file_list: fileList,
  94. action_url: process.env.VUE_APP_API_BASE_URL + '/api/v1/example/uploadFile',
  95. image_info: [],
  96. num: 0,
  97. dir_path: "D:\\www\\xing\\electron-egg",
  98. };
  99. },
  100. methods: {
  101. openDirectry (id) {
  102. const params = {
  103. 'id': id
  104. }
  105. localApi('openDir', params).then(res => {
  106. if (res.code !== 0) {
  107. return false
  108. }
  109. }).catch(err => {
  110. console.log('err:', err)
  111. })
  112. },
  113. handleChange(info) {
  114. const status = info.file.status;
  115. if (status !== 'uploading') {
  116. console.log(info.file);
  117. }
  118. if (status === 'done') {
  119. // 去除list列表
  120. //info.fileList = [];
  121. const uploadRes = info.file.response;
  122. console.log('uploadRes:', uploadRes)
  123. if (uploadRes.code !== 'success') {
  124. this.$message.error(`file upload failed ${uploadRes.code} .`);
  125. return false;
  126. }
  127. this.num++;
  128. const picInfo = uploadRes.data;
  129. picInfo.id = this.num;
  130. picInfo.imageUrlText = 'image url';
  131. this.image_info.push(picInfo);
  132. this.$message.success(`${info.file.name} file uploaded successfully.`);
  133. } else if (status === 'error') {
  134. this.$message.error(`${info.file.name} file upload failed.`);
  135. }
  136. },
  137. selectDir() {
  138. localApi('selectFileDir', {}).then(res => {
  139. if (res.code !== 0) {
  140. return false
  141. }
  142. this.dir_path = res.data.dir;
  143. }).catch(err => {
  144. this.$message.error('异常')
  145. })
  146. },
  147. }
  148. };
  149. </script>
  150. <style lang="less" scoped>
  151. #app-demo-file {
  152. padding: 0px 10px;
  153. text-align: center;
  154. width: 100%;
  155. .one-block-1 {
  156. font-size: 16px;
  157. padding-top: 10px;
  158. }
  159. .one-block-2 {
  160. padding-top: 10px;
  161. }
  162. }
  163. </style>