setting.vue 7.0 KB

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