ResourceDialog.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-bind="$attrs"
  5. title="外部资源引用"
  6. width="600px"
  7. :close-on-click-modal="false"
  8. v-on="$listeners"
  9. @open="onOpen"
  10. @close="onClose"
  11. >
  12. <el-input
  13. v-for="(item, index) in resources"
  14. :key="index"
  15. v-model="resources[index]"
  16. class="url-item"
  17. placeholder="请输入 css 或 js 资源路径"
  18. prefix-icon="el-icon-link"
  19. clearable
  20. >
  21. <el-button
  22. slot="append"
  23. icon="el-icon-delete"
  24. @click="deleteOne(index)"
  25. />
  26. </el-input>
  27. <el-button-group class="add-item">
  28. <el-button
  29. plain
  30. @click="addOne('https://lib.baomitu.com/jquery/1.8.3/jquery.min.js')"
  31. >
  32. jQuery1.8.3
  33. </el-button>
  34. <el-button
  35. plain
  36. @click="addOne('https://unpkg.com/http-vue-loader')"
  37. >
  38. http-vue-loader
  39. </el-button>
  40. <el-button
  41. icon="el-icon-circle-plus-outline"
  42. plain
  43. @click="addOne('')"
  44. >
  45. 添加其他
  46. </el-button>
  47. </el-button-group>
  48. <div slot="footer">
  49. <el-button @click="close">
  50. 取消
  51. </el-button>
  52. <el-button
  53. type="primary"
  54. @click="handelConfirm"
  55. >
  56. 确定
  57. </el-button>
  58. </div>
  59. </el-dialog>
  60. </div>
  61. </template>
  62. <script>
  63. import { deepClone } from '@/utils'
  64. export default {
  65. components: {},
  66. inheritAttrs: false,
  67. props: ['originResource'],
  68. data() {
  69. return {
  70. resources: null
  71. }
  72. },
  73. computed: {},
  74. watch: {},
  75. created() {},
  76. mounted() {},
  77. methods: {
  78. onOpen() {
  79. this.resources = this.originResource.length ? deepClone(this.originResource) : ['']
  80. },
  81. onClose() {
  82. },
  83. close() {
  84. this.$emit('update:visible', false)
  85. },
  86. handelConfirm() {
  87. const results = this.resources.filter(item => !!item) || []
  88. this.$emit('save', results)
  89. this.close()
  90. if (results.length) {
  91. this.resources = results
  92. }
  93. },
  94. deleteOne(index) {
  95. this.resources.splice(index, 1)
  96. },
  97. addOne(url) {
  98. if (this.resources.indexOf(url) > -1) {
  99. this.$message('资源已存在')
  100. } else {
  101. this.resources.push(url)
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .add-item{
  109. margin-top: 8px;
  110. }
  111. .url-item{
  112. margin-bottom: 12px;
  113. }
  114. </style>