Index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div id="app-base-file">
  3. <div class="one-block-1">
  4. <span>
  5. 1. 系统原生对话框
  6. </span>
  7. </div>
  8. <div class="one-block-2">
  9. <a-space>
  10. <a-button @click="messageShow('ipc')">消息提示(ipc)</a-button>
  11. <a-button @click="messageShowConfirm('ipc')">消息提示与确认(ipc)</a-button>
  12. </a-space>
  13. </div>
  14. <div class="one-block-1">
  15. <span>
  16. 2. 选择保存目录
  17. </span>
  18. </div>
  19. <div class="one-block-2">
  20. <a-row>
  21. <a-col :span="12">
  22. <a-input v-model="dir_path" :value="dir_path" addon-before="保存目录" />
  23. </a-col>
  24. <a-col :span="12">
  25. <a-button @click="selectDir">
  26. 修改目录
  27. </a-button>
  28. </a-col>
  29. </a-row>
  30. </div>
  31. <div class="one-block-1">
  32. <span>
  33. 3. 打开文件夹
  34. </span>
  35. </div>
  36. <div class="one-block-2">
  37. <a-list :grid="{ gutter: 16, column: 4 }" :data-source="file_list">
  38. <a-list-item slot="renderItem" slot-scope="item" @click="openDirectry(item.id)">
  39. <a-card :title="item.content">
  40. <a-button type="link">
  41. 打开
  42. </a-button>
  43. </a-card>
  44. </a-list-item>
  45. </a-list>
  46. </div>
  47. <div class="one-block-1">
  48. <span>
  49. 4. 上传文件到图床
  50. </span>
  51. </div>
  52. <div class="one-block-2">
  53. <a-upload-dragger
  54. name="file"
  55. :multiple="true"
  56. :action="action_url"
  57. @change="handleFileChange"
  58. >
  59. <p class="ant-upload-drag-icon">
  60. <a-icon type="inbox" />
  61. </p>
  62. <p class="ant-upload-text">
  63. 点击 或 拖拽文件到这里
  64. </p>
  65. <p class="ant-upload-hint">
  66. 注意:请使用您自己的图床token
  67. </p>
  68. </a-upload-dragger>
  69. </div>
  70. <div class="footer">
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import storage from 'store2'
  76. import { ipcApiRoute } from '@/api/main'
  77. const fileList = [
  78. {
  79. content: '【下载】目录',
  80. id: 'downloads'
  81. },
  82. {
  83. content: '【图片】目录',
  84. id: 'pictures'
  85. },
  86. {
  87. content: '【文档】目录',
  88. id: 'documents'
  89. },
  90. {
  91. content: '【音乐】目录',
  92. id: 'music'
  93. }
  94. ];
  95. export default {
  96. data() {
  97. return {
  98. file_list: fileList,
  99. action_url: '',
  100. image_info: [],
  101. num: 0,
  102. servicAddress: '',
  103. dir_path: "D:\\www\\ee",
  104. };
  105. },
  106. mounted () {
  107. this.getHost();
  108. },
  109. methods: {
  110. getHost () {
  111. const self = this;
  112. this.$ipc.invoke(ipcApiRoute.checkHttpServer, {}).then(r => {
  113. if (r.enable) {
  114. self.servicAddress = r.server;
  115. storage.set('httpServiceConfig', r);
  116. // url转换
  117. const host = r.server || 'http://localhost:7071';
  118. let uri = ipcApiRoute.uploadFile;
  119. let url = uri.split('.').join('/');
  120. this.action_url = host + '/' + url;
  121. }
  122. })
  123. },
  124. openDirectry (id) {
  125. this.$ipc.invoke(ipcApiRoute.openDirectory, {id: id}).then(res => {
  126. //console.log('res:', res)
  127. })
  128. },
  129. selectDir() {
  130. const self = this;
  131. this.$ipc.invoke(ipcApiRoute.selectFolder, '').then(r => {
  132. self.dir_path = r;
  133. self.$message.info(r);
  134. })
  135. },
  136. messageShow(type) {
  137. const self = this;
  138. console.log('[messageShow] type:', type)
  139. this.$ipc.invoke(ipcApiRoute.messageShow, '').then(r => {
  140. self.$message.info(r);
  141. })
  142. },
  143. messageShowConfirm(type) {
  144. const self = this;
  145. console.log('[messageShowConfirm] type:', type)
  146. this.$ipc.invoke(ipcApiRoute.messageShowConfirm, '').then(r => {
  147. self.$message.info(r);
  148. })
  149. },
  150. handleFileChange(info) {
  151. console.log('handleFileChange-----');
  152. if (this.action_url == '') {
  153. this.$message.error('http服务未开启');
  154. return;
  155. }
  156. const status = info.file.status;
  157. if (status !== 'uploading') {
  158. console.log(info.file);
  159. }
  160. if (status === 'done') {
  161. const uploadRes = info.file.response;
  162. console.log('uploadRes:', uploadRes)
  163. if (uploadRes.code !== 'success') {
  164. this.$message.error(`file upload failed ${uploadRes.code} .`);
  165. return false;
  166. }
  167. this.num++;
  168. const picInfo = uploadRes.data;
  169. picInfo.id = this.num;
  170. picInfo.imageUrlText = 'image url';
  171. this.image_info.push(picInfo);
  172. this.$message.success(`${info.file.name} file uploaded successfully.`);
  173. } else if (status === 'error') {
  174. this.$message.error(`${info.file.name} file upload failed.`);
  175. }
  176. },
  177. }
  178. };
  179. </script>
  180. <style lang="less" scoped>
  181. #app-base-file {
  182. padding: 0px 10px;
  183. text-align: left;
  184. width: 100%;
  185. .one-block-1 {
  186. font-size: 16px;
  187. padding-top: 10px;
  188. }
  189. .one-block-2 {
  190. padding-top: 10px;
  191. }
  192. .footer {
  193. padding-top: 10px;
  194. }
  195. }
  196. </style>