index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div>
  3. <el-button class="normal-margin" size="small" type="primary" @click="onShow">从媒体库选择</el-button>
  4. <el-dialog title="媒体库" append-to-body :visible.sync="dialogMediaVisible" width="90%" top="30px">
  5. <list ref="list" :accept="accept" @folderChecked="folderChecked" @toFolderDetail="toFolderDetail">
  6. <!-- <div slot="upload">
  7. <el-button v-if="clickHistory.length > 1" size="mini" type="text" icon="el-icon-back" @click="backFolder">返回上一级</el-button>
  8. </div> -->
  9. </list>
  10. <div class="dialog-footer">
  11. <el-button size="small" @click="dialogMediaVisible = false" class="normal-btn-width">取 消</el-button>
  12. <el-button :disabled="checklist.length !== 1" class="normal-btn-width" type="primary" size="small" @click="bindFileToData">确 定</el-button>
  13. </div>
  14. </el-dialog>
  15. </div>
  16. </template>
  17. <script>
  18. import list from './modules/list.vue'
  19. export default {
  20. props:['bindData','accept'],
  21. components:{
  22. list
  23. },
  24. data () {
  25. return {
  26. dialogMediaVisible:false,
  27. showBtnGroup:false,
  28. folderid:'',
  29. checklist:[],
  30. clickHistory:[0]
  31. }
  32. },
  33. methods:{
  34. onShow () {
  35. this.dialogMediaVisible = true
  36. this.$emit('onShow')
  37. },
  38. // 监听文件选择
  39. folderChecked (arr) {
  40. this.checklist = arr
  41. if (arr.length > 0) {
  42. this.showBtnGroup = true
  43. } else {
  44. this.showBtnGroup = false
  45. }
  46. },
  47. // 监听打开文件夹
  48. toFolderDetail (id) {
  49. this.folderid = id
  50. this.clickHistory.push(id)
  51. console.log(this.folderid)
  52. this.$refs['list'].queryAttachment(id)
  53. },
  54. // 返回上层文件夹
  55. backFolder () {
  56. this.clickHistory.pop()
  57. this.$refs['list'].queryAttachment(this.clickHistory.at(-1))
  58. },
  59. async bindFileToData () {
  60. let obj = {attachmentids:[this.checklist[0].attachmentid]}
  61. obj = Object.assign({},obj,this.bindData)
  62. const res = await this.$api.requested({
  63. "classname": "system.attachment.Attachment",
  64. "method": "createFileLink",
  65. "content": obj
  66. })
  67. this.tool.showMessage(res,()=>{
  68. this.dialogMediaVisible = false
  69. this.$emit('onBindSuccess',{attinfos:JSON.stringify(res)})
  70. })
  71. },
  72. }
  73. }
  74. </script>
  75. <style>
  76. </style>