BgImgDialog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <el-dialog
  3. title="背景图"
  4. :visible.sync="dialogVisible"
  5. width="50%"
  6. :modal="true"
  7. :modal-append-to-body="false"
  8. :appen-to-body="true"
  9. class="bs-dialog-wrap bs-el-dialog"
  10. @closed="$emit('imgUrl', imgUrl)"
  11. >
  12. <div>
  13. <el-upload
  14. ref="uploadDeviceRealImg"
  15. accept=".jpg,.jpeg,.PNG,.JPG"
  16. list-type="picture-card"
  17. :action="actionUrl"
  18. :limit="1"
  19. :on-success="uploadImg"
  20. :file-list="fileList"
  21. :data="fileUploadParam"
  22. :headers="headers"
  23. :on-remove="removeImg"
  24. :before-upload="beforeUpload"
  25. :auto-upload="true"
  26. >
  27. <el-button
  28. :style="{ display: hideUploadImgBtn ? 'none' : '' }"
  29. type="primary"
  30. >
  31. 上传背景图
  32. </el-button>
  33. </el-upload>
  34. <div>
  35. 或链接地址:
  36. <el-input
  37. v-model="imgUrl"
  38. placeholder="请输入链接地址"
  39. clearable
  40. />
  41. </div>
  42. <div>
  43. <el-row
  44. :gutter="8"
  45. style="margin-top: 8px;"
  46. >
  47. <el-col
  48. v-for="img in bgImgList"
  49. :key="img.name"
  50. :md="6"
  51. :lg="6"
  52. :xl="6"
  53. style="max-width: 200px"
  54. >
  55. <el-image
  56. class="bg-img bs-el-img"
  57. :src="img.url"
  58. fit="cover"
  59. @click.native="imgUrl = img.url; dialogVisible = false"
  60. />
  61. </el-col>
  62. </el-row>
  63. </div>
  64. </div>
  65. <div
  66. slot="footer"
  67. class="dialog-footer"
  68. >
  69. <el-button
  70. class="bs-el-button-default"
  71. @click="dialogVisible=false"
  72. >
  73. 取消
  74. </el-button>
  75. <el-button
  76. type="primary"
  77. @click="confirm"
  78. >
  79. 确定
  80. </el-button>
  81. </div>
  82. </el-dialog>
  83. </template>
  84. <script>
  85. import { get } from 'data-room-ui/js/utils/http'
  86. export default {
  87. name: 'BgImgDialog',
  88. props: {
  89. form: {
  90. type: Object,
  91. required: true
  92. }
  93. },
  94. data () {
  95. return {
  96. dialogVisible: false,
  97. hideUploadImgBtn: false,
  98. bgImgList: [],
  99. fileList: [],
  100. imgUrl: '',
  101. fileUploadParam: {
  102. module: 'attachment'
  103. },
  104. headers: {
  105. ...window.BS_CONFIG?.httpConfigs?.headers
  106. },
  107. actionUrl: window?.BS_CONFIG.httpConfigs?.baseURL + '/bigScreen/file/upload'
  108. }
  109. },
  110. computed: {
  111. },
  112. mounted () {
  113. },
  114. methods: {
  115. init () {
  116. this.dialogVisible = true
  117. this.imgUrl = this.form.bg
  118. this.fileList = this.imgUrl
  119. ? [{
  120. name: '背景图',
  121. url: this.imgUrl
  122. }]
  123. : []
  124. this.hideUploadImgBtn = this.fileList.length !== 0
  125. get('/bigScreen/design/bg/list').then(list => {
  126. this.bgImgList = list
  127. })
  128. },
  129. uploadImg (response, file) {
  130. if (response.code !== 200) {
  131. this.$message.error(response.msg)
  132. const idx = this.$refs.uploadDeviceRealImg.uploadFiles.findIndex(
  133. item => item.uid === file.uid
  134. )
  135. this.$refs.uploadDeviceRealImg.uploadFiles.splice(idx, 1)
  136. } else {
  137. this.dialogVisible = false
  138. this.hideUploadImgBtn = true
  139. this.imgUrl = response.data.url
  140. }
  141. },
  142. removeImg (file, fileList) {
  143. this.hideUploadImgBtn = fileList.length !== 0
  144. this.imgUrl = ''
  145. },
  146. beforeUpload (file) {
  147. if (file.size > 30 * 1024 * 1024) {
  148. this.$message.error('上传图片大小不能超过 30MB!')
  149. return false
  150. }
  151. return new Promise(resolve => {
  152. this.$nextTick(() => {
  153. resolve()
  154. })
  155. })
  156. },
  157. confirm () {
  158. this.dialogVisible = false
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .el-upload-list__item.is-ready,
  165. .el-upload-list__item.is-uploading {
  166. display: none !important;
  167. }
  168. ::v-deep .el-upload-list__item {
  169. transition: none !important;
  170. }
  171. ::v-deep .el-upload--picture-card {
  172. width: 0;
  173. height: 0;
  174. display: table-row;
  175. line-height: 0;
  176. background-color: transparent;
  177. }
  178. ::v-deep .el-upload-list__item {
  179. width: 200px;
  180. height: 150px;
  181. margin: 0;
  182. }
  183. .bg-img {
  184. width: 100%;
  185. height: 100px;
  186. cursor: pointer;
  187. }
  188. </style>