Index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div id="app-base-file">
  3. <div class="one-block-1">
  4. <span>
  5. 1. 上传文件到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. 2. 系统原生对话框
  39. </span>
  40. </div>
  41. <div class="one-block-2">
  42. <a-space>
  43. <a-button @click="messageShow('ipc')">消息提示(ipc)</a-button>
  44. <a-button @click="messageShowConfirm('ipc')">消息提示与确认(ipc)</a-button>
  45. <a-button @click="messageShow('http')">消息提示(http)</a-button>
  46. <a-button @click="messageShowConfirm('http')">消息提示与确认(http)</a-button>
  47. </a-space>
  48. </div>
  49. <div class="one-block-1">
  50. <span>
  51. 3. 选择保存目录
  52. </span>
  53. </div>
  54. <div class="one-block-2">
  55. <a-row>
  56. <a-col :span="12">
  57. <a-input v-model="dir_path" :value="dir_path" addon-before="保存目录" />
  58. </a-col>
  59. <a-col :span="12">
  60. <a-button @click="selectDir">
  61. 修改目录
  62. </a-button>
  63. </a-col>
  64. </a-row>
  65. </div>
  66. <div class="one-block-1">
  67. <span>
  68. 4. 打开文件夹
  69. </span>
  70. </div>
  71. <div class="one-block-2">
  72. <a-list :grid="{ gutter: 16, column: 4 }" :data-source="file_list">
  73. <a-list-item slot="renderItem" slot-scope="item" @click="openDirectry(item.id)">
  74. <a-card :title="item.content">
  75. <a-button type="link">
  76. 打开
  77. </a-button>
  78. </a-card>
  79. </a-list-item>
  80. </a-list>
  81. </div>
  82. <div class="footer">
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import { localApi } from '@/api/main'
  88. const fileList = [
  89. {
  90. content: '【下载】目录',
  91. id: 'download'
  92. },
  93. {
  94. content: '【图片】目录',
  95. id: 'picture'
  96. },
  97. {
  98. content: '【文档】目录',
  99. id: 'doc'
  100. },
  101. {
  102. content: '【音乐】目录',
  103. id: 'music'
  104. }
  105. ];
  106. export default {
  107. data() {
  108. return {
  109. file_list: fileList,
  110. action_url: process.env.VUE_APP_API_BASE_URL + '/api/v1/example/uploadFile',
  111. image_info: [],
  112. num: 0,
  113. dir_path: "D:\\www\\xing\\electron-egg",
  114. };
  115. },
  116. methods: {
  117. openDirectry (id) {
  118. const params = {
  119. 'id': id
  120. }
  121. localApi('openDir', params).then(res => {
  122. if (res.code !== 0) {
  123. return false
  124. }
  125. }).catch(err => {
  126. console.log('err:', err)
  127. })
  128. },
  129. handleChange(info) {
  130. const status = info.file.status;
  131. if (status !== 'uploading') {
  132. console.log(info.file);
  133. }
  134. if (status === 'done') {
  135. // 去除list列表
  136. //info.fileList = [];
  137. const uploadRes = info.file.response;
  138. console.log('uploadRes:', uploadRes)
  139. if (uploadRes.code !== 'success') {
  140. this.$message.error(`file upload failed ${uploadRes.code} .`);
  141. return false;
  142. }
  143. this.num++;
  144. const picInfo = uploadRes.data;
  145. picInfo.id = this.num;
  146. picInfo.imageUrlText = 'image url';
  147. this.image_info.push(picInfo);
  148. this.$message.success(`${info.file.name} file uploaded successfully.`);
  149. } else if (status === 'error') {
  150. this.$message.error(`${info.file.name} file upload failed.`);
  151. }
  152. },
  153. selectDir() {
  154. localApi('selectFileDir', {}).then(res => {
  155. if (res.code !== 0) {
  156. return false
  157. }
  158. console.log('res.data.dir:', res.data.dir)
  159. this.dir_path = res.data.dir;
  160. }).catch(err => {
  161. this.$message.error('异常')
  162. })
  163. },
  164. messageShow(type) {
  165. const self = this;
  166. console.log('[messageShow] type:', type)
  167. if (type == 'http') {
  168. localApi('messageShow', {}).then(res => {
  169. if (res.code !== 0) {
  170. return false
  171. }
  172. console.log('res:', res)
  173. }).catch(err => {
  174. self.$message.error(err + '异常')
  175. })
  176. } else {
  177. self.$ipcCallMain('example.messageShow', '').then(r => {
  178. self.$message.info(r);
  179. })
  180. }
  181. },
  182. messageShowConfirm(type) {
  183. const self = this;
  184. console.log('[messageShowConfirm] type:', type)
  185. if (type == 'http') {
  186. localApi('messageShowConfirm', {}).then(res => {
  187. if (res.code !== 0) {
  188. return false
  189. }
  190. console.log('res:', res)
  191. }).catch(err => {
  192. self.$message.error(err + '异常')
  193. })
  194. } else {
  195. self.$ipcCallMain('example.messageShowConfirm', '').then(r => {
  196. self.$message.info(r);
  197. })
  198. }
  199. },
  200. }
  201. };
  202. </script>
  203. <style lang="less" scoped>
  204. #app-base-file {
  205. padding: 0px 10px;
  206. text-align: left;
  207. width: 100%;
  208. .one-block-1 {
  209. font-size: 16px;
  210. padding-top: 10px;
  211. }
  212. .one-block-2 {
  213. padding-top: 10px;
  214. }
  215. .footer {
  216. padding-top: 10px;
  217. }
  218. }
  219. </style>