setting.vue 6.3 KB

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