AttachmentList.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!-- 附件 -->
  2. <template>
  3. <div class="hello">
  4. <Header> </Header>
  5. <el-container class="container-narrow">
  6. <el-dialog :title="$t('attachment')" :visible.sync="dialogTableVisible" >
  7. <el-upload
  8. class="upload-file"
  9. :action="uploadUrl"
  10. :on-success="clearFiles"
  11. :on-error="clearFiles"
  12. :data="uploadData"
  13. ref="uploadFile"
  14. v-if="manage"
  15. >
  16. <el-button size="small" type="primary">{{$t('upload_file')}}</el-button><small>&nbsp;&nbsp;&nbsp;{{$t('file_size_tips')}}</small>
  17. </el-upload>
  18. <el-table :data="content">
  19. <el-table-column property="addtime" :label="$t('add_time')" width="170"></el-table-column>
  20. <el-table-column property="display_name" :label="$t('file_name')" ></el-table-column>
  21. <el-table-column
  22. :label="$t('operation')"
  23. width="150">
  24. <template slot-scope="scope">
  25. <el-button @click="downloadFile(scope.row)" type="text" size="small">{{$t('download')}}</el-button>
  26. <el-button @click="insertFile(scope.row)" type="text" size="small" v-if="manage" >{{$t('insert')}}</el-button>
  27. <el-button type="text" size="small" @click="deleteFile(scope.row)" v-if="manage">{{$t('delete')}}</el-button>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. </el-dialog>
  32. </el-container>
  33. <Footer> </Footer>
  34. <div class=""></div>
  35. </div>
  36. </template>
  37. <style>
  38. </style>
  39. <script>
  40. export default {
  41. props:{
  42. callback:'',
  43. page_id:'',
  44. item_id:'',
  45. manage:true,
  46. },
  47. data () {
  48. return {
  49. currentDate: new Date(),
  50. content: [],
  51. dialogTableVisible: false,
  52. uploadUrl:DocConfig.server+'/api/page/upload',
  53. };
  54. },
  55. components:{
  56. },
  57. computed:{
  58. uploadData:function(){
  59. return {
  60. page_id:this.page_id,
  61. item_id:this.item_id,
  62. }
  63. }
  64. },
  65. methods:{
  66. get_content(){
  67. var that = this ;
  68. var url = DocConfig.server+'/api/page/uploadList';
  69. var params = new URLSearchParams();
  70. params.append('page_id', this.page_id);
  71. that.axios.post(url, params)
  72. .then(function (response) {
  73. if (response.data.error_code === 0 ) {
  74. that.dialogTableVisible = true ;
  75. //that.$message.success("加载成功");
  76. var json = response.data.data ;
  77. that.content = response.data.data ;
  78. }else{
  79. that.dialogTableVisible = false;
  80. that.$alert(response.data.error_message);
  81. }
  82. });
  83. },
  84. show(){
  85. this.get_content();
  86. },
  87. downloadFile(row){
  88. var url = row.url ;
  89. window.open(url);
  90. },
  91. deleteFile(row){
  92. var that = this ;
  93. this.$confirm(that.$t('comfirm_delete'), ' ', {
  94. confirmButtonText: that.$t('confirm'),
  95. cancelButtonText: that.$t('cancel'),
  96. type: 'warning'
  97. }).then(() => {
  98. var file_id = row['file_id'] ;
  99. var that = this ;
  100. var url = DocConfig.server+'/api/page/deleteUploadFile';
  101. var params = new URLSearchParams();
  102. params.append('file_id', file_id);
  103. that.axios.post(url, params)
  104. .then(function (response) {
  105. if (response.data.error_code === 0 ) {
  106. that.get_content();
  107. }else{
  108. that.$alert(response.data.error_message);
  109. }
  110. })
  111. });
  112. },
  113. clearFiles(){
  114. let childRef = this.$refs.uploadFile ;//获取子组件
  115. childRef.clearFiles() ;
  116. this.get_content();
  117. },
  118. insertFile(row){
  119. var val = '['+row['display_name']+']('+row['url']+' "['+row['display_name']+'")';
  120. this.callback(val);
  121. this.dialogTableVisible = false;
  122. }
  123. },
  124. mounted () {
  125. }
  126. }
  127. </script>