setting.vue 5.9 KB

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