setting.vue 5.9 KB

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