setting.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <!--
  2. * @description: 标题属性设置面板
  3. * @Date: 2022-08-17 16:53:28
  4. * @Author: shiyi
  5. -->
  6. <template>
  7. <div class="bs-setting-wrap">
  8. <el-form
  9. ref="form"
  10. label-width="100px"
  11. label-position="left"
  12. :model="config"
  13. :rules="rules"
  14. class="bs-el-form"
  15. >
  16. <SettingTitle>标题</SettingTitle>
  17. <div class="lc-field-body">
  18. <el-form-item
  19. label="标题"
  20. label-width="100px"
  21. prop="title"
  22. >
  23. <el-input
  24. v-model="config.title"
  25. placeholder="请输入标题"
  26. clearable
  27. />
  28. </el-form-item>
  29. </div>
  30. <SettingTitle>位置</SettingTitle>
  31. <div class="lc-field-body">
  32. <PosWhSetting :config="config" />
  33. </div>
  34. <SettingTitle>基础</SettingTitle>
  35. <div class="lc-field-body">
  36. <el-form-item
  37. label="URL"
  38. label-width="100px"
  39. prop="customize.url"
  40. style="margin-bottom: 14px"
  41. >
  42. <el-upload
  43. class="bs-el-upload"
  44. :class="{ hide: fileList.length >= 1 }"
  45. :action="upLoadUrl"
  46. :data="fileUploadParam"
  47. :headers="headers"
  48. :accept="accept"
  49. :file-list="fileList"
  50. :auto-upload="true"
  51. :limit="1"
  52. list-type="picture-card"
  53. :on-success="handleUploadSuccess"
  54. :on-error="handleUploadError"
  55. :before-upload="beforeUpload"
  56. >
  57. <i
  58. slot="default"
  59. class="el-icon-plus"
  60. />
  61. <div
  62. slot="file"
  63. slot-scope="{ file }"
  64. >
  65. <img
  66. class="el-upload-list__item-thumbnail"
  67. :src="file.url"
  68. alt=""
  69. >
  70. <span class="el-upload-list__item-actions">
  71. <span
  72. class="el-upload-list__item-delete"
  73. @click="handleRemove(file)"
  74. >
  75. <i class="el-icon-delete" />
  76. </span>
  77. </span>
  78. </div>
  79. <el-input
  80. slot="tip"
  81. v-model="config.customize.url"
  82. class="upload-tip"
  83. placeholder="或输入URL地址"
  84. clearable
  85. />
  86. </el-upload>
  87. </el-form-item>
  88. <el-form-item
  89. label="不透明度"
  90. label-width="100px"
  91. >
  92. <el-input-number
  93. v-model="config.customize.opacity"
  94. class="bs-el-input-number"
  95. placeholder="请输入不透明度"
  96. :min="0.01"
  97. :max="1"
  98. :precision="2"
  99. :step="0.01"
  100. />
  101. </el-form-item>
  102. </div>
  103. </el-form>
  104. </div>
  105. </template>
  106. <script>
  107. import SettingTitle from 'data-room-ui/SettingTitle/index.vue'
  108. import PosWhSetting from 'data-room-ui/BigScreenDesign/RightSetting/PosWhSetting.vue'
  109. export default {
  110. name: 'PicSetting',
  111. components: {
  112. PosWhSetting,
  113. SettingTitle
  114. },
  115. data () {
  116. return {
  117. upLoadUrl:
  118. window.BS_CONFIG?.httpConfigs?.baseURL + '/bigScreen/file/upload',
  119. fileUploadParam: {
  120. module: 'form'
  121. },
  122. headers: {
  123. ...window.BS_CONFIG?.httpConfigs?.headers
  124. },
  125. fileList: [],
  126. accept: 'image/*',
  127. hideUpload: false,
  128. rules: {
  129. 'customize.url': [
  130. // 地址校验
  131. {
  132. validator: (rule, value, callback) => {
  133. if (value) {
  134. const reg = /^(http|https):\/\/([\w.]+\/?)\S*/
  135. if (!reg.test(value)) {
  136. callback(new Error('请输入正确的URL地址'))
  137. } else {
  138. callback()
  139. }
  140. } else {
  141. callback()
  142. }
  143. },
  144. trigger: 'blur'
  145. }
  146. ]
  147. }
  148. }
  149. },
  150. computed: {
  151. config: {
  152. get () {
  153. return this.$store.state.bigScreen.activeItemConfig
  154. },
  155. set (val) {
  156. this.$store.state.bigScreen.activeItemConfig = val
  157. }
  158. }
  159. },
  160. watch: {
  161. 'config.customize.url': function (val) {
  162. if (val) {
  163. this.fileList = [
  164. {
  165. name: this.config.title,
  166. url: this.config.customize.url
  167. }
  168. ]
  169. } else {
  170. this.fileList = []
  171. }
  172. }
  173. },
  174. mounted () {
  175. if (this.config.customize.url) {
  176. this.fileList = [
  177. {
  178. name: this.config.title,
  179. url: this.config.customize.url
  180. }
  181. ]
  182. } else {
  183. this.fileList = []
  184. }
  185. },
  186. methods: {
  187. handleUploadSuccess (res) {
  188. if (res.code === 200) {
  189. this.config.customize.url = res.data.url
  190. this.fileList = [
  191. {
  192. name: this.config.title,
  193. url: this.config.customize.url
  194. }
  195. ]
  196. } else {
  197. this.$message.error(res.msg)
  198. this.fileList = []
  199. }
  200. },
  201. handleUploadError () {
  202. this.$message.error('上传失败')
  203. },
  204. handleRemove () {
  205. this.fileList = []
  206. this.config.customize.url = ''
  207. },
  208. beforeUpload (file) {
  209. const isLt2M = file.size / 1024 / 1024 < 2
  210. if (!isLt2M) {
  211. this.$message.error('上传图片大小不能超过 2MB!')
  212. }
  213. return isLt2M
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. @import '../../assets/style/settingWrap.scss';
  220. .bs-slider {
  221. .el-input-number__decrease {
  222. background: var(--bs-el-background-1);
  223. border-right: 1px solid var(--bs-background-1);
  224. }
  225. .el-input-number__increase {
  226. background: var(--bs-el-background-1);
  227. border-left: 1px solid var(--bs-background-1);
  228. }
  229. }
  230. .bs-setting-wrap {
  231. padding-top: 16px;
  232. ::v-deep .hide .el-upload--picture-card {
  233. display: none !important;
  234. }
  235. ::v-deep .el-upload-list__item {
  236. transition: none !important;
  237. }
  238. ::v-deep .el-upload--picture-card {
  239. margin-bottom: 12px !important;
  240. }
  241. }
  242. .lc-field-body {
  243. padding: 12px 16px;
  244. }
  245. </style>