opendir.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div>
  3. <div class="i-layout-page-header">
  4. <PageHeader class="product_tabs" title="文件管理" hidden-breadcrumb></PageHeader>
  5. </div>
  6. <Card :bordered="false" dis-hover class="ivu-mt">
  7. <div class="backs" @click="goBack">
  8. <Icon type="ios-folder-outline" class="mr5"/><span>返回上级</span>
  9. </div>
  10. <Table ref="selection" :columns="columns4" :data="tabList" :loading="loading"
  11. no-data-text="暂无数据" highlight-row class="mt20" @on-current-change="currentChange"
  12. no-filtered-data-text="暂无筛选结果">
  13. <template slot-scope="{ row }" slot="filename">
  14. <Icon type="ios-folder-outline" v-if="row.isDir" class="mr5"/>
  15. <Icon type="ios-document-outline" v-else class="mr5"/>
  16. <span>{{row.filename}}</span>
  17. </template>
  18. <template slot-scope="{ row }" slot="isWritable">
  19. <span v-text="row.isWritable?'是':'否'"></span>
  20. </template>
  21. <template slot-scope="{ row, index }" slot="action">
  22. <a @click="open(row)" v-if="row.isDir">打开</a>
  23. <a @click="edit(row)" v-else>编辑</a>
  24. </template>
  25. </Table>
  26. </Card>
  27. <Modal v-model="modals" scrollable footer-hide closable :title="title" :mask-closable="false" width="900">
  28. <Button type="primary" id="savefile" class="mr5 mb15" @click="savefile">保存</Button>
  29. <Button id="undo" class="mr5 mb15" @click="undofile">撤销</Button>
  30. <!-- <Button id="redo" class="mr5 mb15" @click="redofile">回退</Button>-->
  31. <!-- <Button id="refresh" class="mb15" @click="refreshfile">刷新</Button>-->
  32. <textarea ref="mycode" class="codesql public_text" v-model="code"></textarea>
  33. <Spin size="large" fix v-if="spinShow"></Spin>
  34. </Modal>
  35. </div>
  36. </template>
  37. <script>
  38. import { opendirListApi, openfileApi, savefileApi } from '@/api/system';
  39. import CodeMirror from 'codemirror/lib/codemirror'
  40. import 'codemirror/theme/ambiance.css';
  41. require('codemirror/mode/javascript/javascript');
  42. export default {
  43. name: 'opendir',
  44. data () {
  45. return {
  46. code: '',
  47. modals: false,
  48. spinShow: false,
  49. loading: false,
  50. tabList: [],
  51. columns4: [
  52. {
  53. title: '文件/文件夹名',
  54. slot: 'filename',
  55. minWidth: 150,
  56. back: '返回上级'
  57. },
  58. {
  59. title: '文件/文件夹路径',
  60. key: 'real_path',
  61. minWidth: 150
  62. },
  63. {
  64. title: '文件/文件夹大小',
  65. key: 'size',
  66. minWidth: 100
  67. },
  68. {
  69. title: '是否可写',
  70. slot: 'isWritable',
  71. minWidth: 100
  72. },
  73. {
  74. title: '更新时间',
  75. key: 'mtime',
  76. minWidth: 150
  77. },
  78. {
  79. title: 'Action',
  80. slot: 'action',
  81. minWidth: 150
  82. }
  83. ],
  84. formItem: {
  85. dir: '',
  86. superior: 0,
  87. filedir: ''
  88. },
  89. rows: {},
  90. pathname: '',
  91. title: ''
  92. }
  93. },
  94. mounted () {
  95. this.editor = CodeMirror.fromTextArea(this.$refs.mycode, {
  96. value: '', // 文本域默认显示的文本
  97. mode: 'text/javascript',
  98. theme: 'ambiance', // CSS样式选择
  99. indentUnit: 4, // 缩进单位,默认2
  100. smartIndent: true, // 是否智能缩进
  101. tabSize: 4, // Tab缩进,默认4
  102. readOnly: false, // 是否只读,默认false
  103. showCursorWhenSelecting: true,
  104. lineNumbers: true // 是否显示行号
  105. })
  106. },
  107. created () {
  108. this.getList();
  109. },
  110. methods: {
  111. // 点击行
  112. currentChange (currentRow) {
  113. if (currentRow.isDir) {
  114. this.open(currentRow);
  115. } else {
  116. this.edit(currentRow);
  117. }
  118. },
  119. // 列表
  120. getList () {
  121. this.loading = true;
  122. opendirListApi(this.formItem).then(async res => {
  123. let data = res.data
  124. this.tabList = data.list;
  125. this.dir = data.dir;
  126. this.loading = false;
  127. }).catch(res => {
  128. this.loading = false;
  129. this.$Message.error(res.msg);
  130. })
  131. },
  132. // 返回上级
  133. goBack () {
  134. this.formItem = {
  135. dir: this.dir,
  136. superior: 1,
  137. filedir: ''
  138. }
  139. this.getList()
  140. },
  141. // 打开
  142. open (row) {
  143. this.rows = row;
  144. this.formItem = {
  145. dir: row.path,
  146. superior: 0,
  147. filedir: row.filename
  148. }
  149. this.getList()
  150. },
  151. // 编辑
  152. edit (row) {
  153. this.modals = true;
  154. this.spinShow = true;
  155. this.pathname = row.pathname;
  156. this.title = row.filename;
  157. openfileApi(row.pathname).then(async res => {
  158. let data = res.data;
  159. this.code = data.content;
  160. this.editor.setValue(this.code);
  161. this.spinShow = false;
  162. }).catch(res => {
  163. this.spinShow = false;
  164. this.$Message.error(res.msg);
  165. })
  166. },
  167. // 保存
  168. savefile () {
  169. let data = {
  170. comment: this.editor.getValue(),
  171. filepath: this.pathname
  172. };
  173. savefileApi(data).then(async res => {
  174. this.$Message.success(res.msg);
  175. this.modals = false;
  176. }).catch(res => {
  177. this.$Message.error(res.msg);
  178. })
  179. },
  180. // 撤销
  181. undofile () {
  182. this.editor.undo();
  183. },
  184. redofile () {
  185. this.editor.redo();
  186. },
  187. // 刷新
  188. refreshfile () {
  189. this.editor.refresh();
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped lang="stylus">
  195. .mt20
  196. >>>.ivu-icon-ios-folder-outline
  197. font-size 14px !important
  198. >>> .ivu-icon-ios-document-outline
  199. font-size 18px !important
  200. >>> .ivu-table-row
  201. cursor pointer
  202. .mr5
  203. margin-right 5px
  204. .backs
  205. cursor pointer
  206. display inline-block
  207. </style>