setting.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 'packages/SettingTitle/index.vue'
  108. import PosWhSetting from 'packages/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. { required: true, message: '请输入URL地址', trigger: 'blur' },
  131. // 地址校验
  132. {
  133. validator: (rule, value, callback) => {
  134. if (value) {
  135. const reg = /^(http|https):\/\/([\w.]+\/?)\S*/
  136. if (!reg.test(value)) {
  137. callback(new Error('请输入正确的URL地址'))
  138. } else {
  139. callback()
  140. }
  141. } else {
  142. callback()
  143. }
  144. },
  145. trigger: 'blur'
  146. }
  147. ]
  148. }
  149. }
  150. },
  151. computed: {
  152. config: {
  153. get () {
  154. return this.$store.state.bigScreen.activeItemConfig
  155. },
  156. set (val) {
  157. this.$store.state.bigScreen.activeItemConfig = val
  158. }
  159. }
  160. },
  161. watch: {
  162. 'config.customize.url': function (val) {
  163. if (val) {
  164. this.fileList = [
  165. {
  166. name: this.config.title,
  167. url: this.config.customize.url
  168. }
  169. ]
  170. } else {
  171. this.fileList = []
  172. }
  173. }
  174. },
  175. mounted () {
  176. if (this.config.customize.url) {
  177. this.fileList = [
  178. {
  179. name: this.config.title,
  180. url: this.config.customize.url
  181. }
  182. ]
  183. } else {
  184. this.fileList = []
  185. }
  186. },
  187. methods: {
  188. handleUploadSuccess (res) {
  189. if (res.code === 200) {
  190. this.config.customize.url = res.data.url
  191. this.fileList = [
  192. {
  193. name: this.config.title,
  194. url: this.config.customize.url
  195. }
  196. ]
  197. } else {
  198. this.$message.error(res.msg)
  199. this.fileList = []
  200. }
  201. },
  202. handleUploadError () {
  203. this.$message.error('上传失败')
  204. },
  205. handleRemove () {
  206. this.fileList = []
  207. this.config.customize.url = ''
  208. },
  209. beforeUpload (file) {
  210. const isLt2M = file.size / 1024 / 1024 < 2
  211. if (!isLt2M) {
  212. this.$message.error('上传图片大小不能超过 2MB!')
  213. }
  214. return isLt2M
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. @import '../../assets/style/settingWrap.scss';
  221. .bs-slider {
  222. .el-input-number__decrease {
  223. background: var(--bs-el-background-1);
  224. border-right: 1px solid var(--bs-background-1);
  225. }
  226. .el-input-number__increase {
  227. background: var(--bs-el-background-1);
  228. border-left: 1px solid var(--bs-background-1);
  229. }
  230. }
  231. .bs-setting-wrap {
  232. padding-top: 16px;
  233. ::v-deep .hide .el-upload--picture-card {
  234. display: none !important;
  235. }
  236. ::v-deep.el-upload-list__item {
  237. transition: none !important;
  238. }
  239. ::v-deep .el-upload--picture-card {
  240. margin-bottom: 12px !important;
  241. }
  242. }
  243. .lc-field-body {
  244. padding: 12px 16px;
  245. }
  246. </style>