BgImgDialog.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 { getFileUrl } from 'data-room-ui/js/utils/file'
  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.customTheme === 'light' ? this.form.lightBg : this.form.bg
  118. this.fileList = this.getCoverPicture(this.imgUrl) ? [{ name: '背景图', url: this.getCoverPicture(this.imgUrl) }] : []
  119. this.hideUploadImgBtn = this.fileList.length !== 0
  120. this.$dataRoomAxios.get('/bigScreen/design/bg/list').then(list => {
  121. this.bgImgList = list
  122. })
  123. },
  124. uploadImg (response, file) {
  125. if (response.code !== 200) {
  126. this.$message.error(response.msg)
  127. const idx = this.$refs.uploadDeviceRealImg.uploadFiles.findIndex(
  128. item => item.uid === file.uid
  129. )
  130. this.$refs.uploadDeviceRealImg.uploadFiles.splice(idx, 1)
  131. } else {
  132. this.dialogVisible = false
  133. this.hideUploadImgBtn = true
  134. this.imgUrl = response.data.url
  135. }
  136. },
  137. removeImg (file, fileList) {
  138. this.hideUploadImgBtn = fileList.length !== 0
  139. this.imgUrl = ''
  140. },
  141. beforeUpload (file) {
  142. if (file.size > 30 * 1024 * 1024) {
  143. this.$message.error('上传图片大小不能超过 30MB!')
  144. return false
  145. }
  146. return new Promise(resolve => {
  147. this.$nextTick(() => {
  148. resolve()
  149. })
  150. })
  151. },
  152. confirm () {
  153. this.dialogVisible = false
  154. },
  155. /**
  156. * 获取图片访问地址,如果是相对路径则拼接上文件访问前缀地址
  157. * @param url
  158. * @returns {*}
  159. */
  160. getCoverPicture (url) {
  161. return getFileUrl(url)
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .el-upload-list__item.is-ready,
  168. .el-upload-list__item.is-uploading {
  169. display: none !important;
  170. }
  171. ::v-deep .el-upload-list__item {
  172. transition: none !important;
  173. }
  174. ::v-deep .el-upload--picture-card {
  175. width: 0;
  176. height: 0;
  177. display: table-row;
  178. line-height: 0;
  179. background-color: transparent;
  180. }
  181. ::v-deep .el-upload-list__item {
  182. width: 200px;
  183. height: 150px;
  184. margin: 0;
  185. }
  186. .bg-img {
  187. width: 100%;
  188. height: 100px;
  189. cursor: pointer;
  190. }
  191. </style>