BgImgDialog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. export default {
  86. name: 'BgImgDialog',
  87. props: {
  88. form: {
  89. type: Object,
  90. required: true
  91. }
  92. },
  93. data () {
  94. return {
  95. dialogVisible: false,
  96. hideUploadImgBtn: false,
  97. bgImgList: [],
  98. fileList: [],
  99. imgUrl: '',
  100. fileUploadParam: {
  101. module: 'attachment'
  102. },
  103. headers: {
  104. ...window.BS_CONFIG?.httpConfigs?.headers
  105. },
  106. actionUrl: window?.BS_CONFIG.httpConfigs?.baseURL + '/bigScreen/file/upload'
  107. }
  108. },
  109. computed: {
  110. },
  111. mounted () {
  112. },
  113. methods: {
  114. init () {
  115. this.dialogVisible = true
  116. this.imgUrl = this.form.customTheme === 'light' ? this.form.bg : this.form.lightBg
  117. this.fileList = this.imgUrl
  118. ? [{
  119. name: '背景图',
  120. url: this.imgUrl
  121. }]
  122. : []
  123. this.hideUploadImgBtn = this.fileList.length !== 0
  124. this.$dataRoomAxios.get('/bigScreen/design/bg/list').then(list => {
  125. this.bgImgList = list
  126. })
  127. },
  128. uploadImg (response, file) {
  129. if (response.code !== 200) {
  130. this.$message.error(response.msg)
  131. const idx = this.$refs.uploadDeviceRealImg.uploadFiles.findIndex(
  132. item => item.uid === file.uid
  133. )
  134. this.$refs.uploadDeviceRealImg.uploadFiles.splice(idx, 1)
  135. } else {
  136. this.dialogVisible = false
  137. this.hideUploadImgBtn = true
  138. this.imgUrl = response.data.url
  139. }
  140. },
  141. removeImg (file, fileList) {
  142. this.hideUploadImgBtn = fileList.length !== 0
  143. this.imgUrl = ''
  144. },
  145. beforeUpload (file) {
  146. if (file.size > 30 * 1024 * 1024) {
  147. this.$message.error('上传图片大小不能超过 30MB!')
  148. return false
  149. }
  150. return new Promise(resolve => {
  151. this.$nextTick(() => {
  152. resolve()
  153. })
  154. })
  155. },
  156. confirm () {
  157. this.dialogVisible = false
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .el-upload-list__item.is-ready,
  164. .el-upload-list__item.is-uploading {
  165. display: none !important;
  166. }
  167. ::v-deep .el-upload-list__item {
  168. transition: none !important;
  169. }
  170. ::v-deep .el-upload--picture-card {
  171. width: 0;
  172. height: 0;
  173. display: table-row;
  174. line-height: 0;
  175. background-color: transparent;
  176. }
  177. ::v-deep .el-upload-list__item {
  178. width: 200px;
  179. height: 150px;
  180. margin: 0;
  181. }
  182. .bg-img {
  183. width: 100%;
  184. height: 100px;
  185. cursor: pointer;
  186. }
  187. </style>