diy-icon-set.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template id="diy-icon-set">
  2. <diy-style-contain :title="title" :show-title="showTitle" :contain-style="containStyle">
  3. <div v-for="(item, index) in iconList" :key="index" :style="[iconSetStyle]" @click="closePop">
  4. <div class="icon-set-title" v-if="item.title">{{ item.title }}</div>
  5. <div class="icon-set-list">
  6. <!-- 关闭图标 -->
  7. <div class="icon-set-close" flex="cross:center" @click.stop="closeHandle(item, index)" v-if="showClose">
  8. <i class="el-icon-close"></i>
  9. </div>
  10. <!-- 删除弹窗 -->
  11. <diy-confirm-popup
  12. :title="popTitle"
  13. :show="cardIndex == index && visible"
  14. confirm-text="删除"
  15. :show-confrim-btn="showConfrimBtn"
  16. @close="closePop"
  17. @confirm="delCards($event, index)"
  18. ></diy-confirm-popup>
  19. <div v-if="item.slot">
  20. <slot :name="item.slot" :item="item" :index="index"></slot>
  21. </div>
  22. <!-- 内容 -->
  23. <div class="icon-set-items" flex="cross:center" v-if="set_style != 'text'">
  24. <div class="icon-set-list-name diy-text-font">{{ type == 1 ? '图片' : '图标' }}</div>
  25. <div class="icon-set-list-content">
  26. <com-attachment :multiple="false" :max="1" type="images" @selected="coverPic($event, item)">
  27. <div class="content-upload" :style="{width: widthImg + 'px', height: heightImg + 'px'}" flex="cross:center main:center" v-if="!item.img">
  28. <i class="el-icon-plus"></i>
  29. </div>
  30. <div class="content-img" :style="{width: widthImg + 'px', height: heightImg + 'px'}" flex="cross:center main:center" v-else>
  31. <el-image style="width: 100%; height: 100%;border-radius: 8px;" :src="item.img"></el-image>
  32. <div class="img-replace">替换</div>
  33. <div class="icon-close" @click.stop="delPic(item, index)">
  34. <i class="el-icon-close"></i>
  35. </div>
  36. </div>
  37. </com-attachment>
  38. <div class="tips-text" v-if="suggestText">{{ suggestText }}</div>
  39. </div>
  40. </div>
  41. <div class="icon-set-items" flex="cross:center" v-if="set_style != 'text' && type == 1 && tagSwitch">
  42. <div class="icon-set-list-name diy-text-font">标签</div>
  43. <div class="icon-set-list-content" flex="cross:center">
  44. <el-switch v-model="item.is_show_tag" active-color="#2D8CF0" inactive-color="#999999" @change="iconSetChange($event, item, 'is_show_tag')"></el-switch>
  45. <span class="diy-text-font" style="padding-left: 7px;font-weight: 500;">{{ item.is_show_tag ? '开启' : '关闭' }}</span>
  46. </div>
  47. </div>
  48. <div class="icon-set-items" flex="cross:center" v-if="item.is_show_tag && set_style != 'text' && type == 1">
  49. <div class="icon-set-list-name diy-text-font">标签内容</div>
  50. <div class="icon-set-list-content" flex="cross:center">
  51. <el-input size="small" v-model="item.tags" placeholder="请输入内容" maxlength="2" @input="iconSetChange($event, item, 'tags')" show-word-limit></el-input>
  52. </div>
  53. </div>
  54. <div class="icon-set-items" flex="cross:center" v-if="item.is_show_tag && set_style != 'text' && type == 1">
  55. <div class="icon-set-list-name diy-text-font">标签背景</div>
  56. <div class="icon-set-list-content" flex="cross:center">
  57. <el-color-picker flex="cross:center" v-model="item.tagsBgColor" :show-alpha="showAlpha" @change="iconSetChange($event, item, 'tagsBgColor')"></el-color-picker>
  58. </div>
  59. </div>
  60. <div class="icon-set-items" flex="cross:center" v-if="item.is_show_tag && set_style != 'text' && type == 1">
  61. <div class="icon-set-list-name diy-text-font">标签文字</div>
  62. <div class="icon-set-list-content" flex="cross:center">
  63. <el-color-picker flex="cross:center" v-model="item.tagsTextColor" :show-alpha="showAlpha" @change="iconSetChange($event, item, 'tagsTextColor')"></el-color-picker>
  64. </div>
  65. </div>
  66. <div class="icon-set-items" flex="cross:center" v-if="set_style != 'image'">
  67. <div class="icon-set-list-name diy-text-font">文字</div>
  68. <div class="icon-set-list-content" flex="cross:center">
  69. <el-input size="small" v-model="item.btnText" placeholder="请输入内容" @input="iconSetChange($event, item, 'btnText')" maxlength="5" show-word-limit></el-input>
  70. </div>
  71. </div>
  72. <div class="icon-set-items" flex="cross:center" v-if="showLink">
  73. <div class="icon-set-list-name diy-text-font">链接</div>
  74. <div class="icon-set-list-content" flex="cross:center">
  75. <com-pick-link @selected="selectedUrl($event, item)" :default-tabs="defaultTabs" :show-id="showId">
  76. <diy-url :text="item.link_params && (item.link_params.title || item.link_params.open_type)" @add="addUrl(index)"></diy-url>
  77. </com-pick-link>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <div class="add-btns" @click="addClick" v-if="showAddBtn && list.length < maxIconLength">+ 添加<span v-if="maxIconLength">{{ list.length }}/{{ maxIconLength }}</span></div>
  83. </diy-style-contain>
  84. </template>
  85. <script>
  86. /**
  87. * 图标设置组件
  88. *
  89. */
  90. Vue.component('diy-icon-set', {
  91. template: '#diy-icon-set',
  92. name: 'diy-icon-set',
  93. props: {
  94. title: { // 组件标题, 传值显示标题, 不传就不显示
  95. type: String,
  96. default: ''
  97. },
  98. containStyle: { // 包裹容器的样式
  99. type: Object,
  100. default: () => {}
  101. },
  102. /**
  103. * list 的数据格式
  104. * {
  105. title: '', // 标题,有就显示,没有就不显示
  106. img: 'resources/img/decorate/default_btn1.png', // 图片
  107. icon: 'el-icon-setting', // 图标
  108. is_show_tag: false, // 是否展示标签
  109. tags: '热门', // 标签内容
  110. tagsBgColor: '#f83287', // 标签背景色
  111. tagsTextColor: '#ffffff', // 标签文字颜色
  112. btnText: '按钮文字' // 按钮文字
  113. link_params: null, // 链接内容
  114. }
  115. */
  116. list: {
  117. type: Array,
  118. default: () => {
  119. return []
  120. }
  121. },
  122. widthImg: { // 图片的宽度
  123. type: Number,
  124. default: 50
  125. },
  126. heightImg: { // 图片的高度
  127. type: Number,
  128. default: 50
  129. },
  130. showClose: { // 是否展示删除按钮
  131. type: Boolean,
  132. default: true
  133. },
  134. tagSwitch: { // 是否需要标签开关
  135. type: Boolean,
  136. default: false
  137. },
  138. showLink: { // 是否展示链接
  139. type: Boolean,
  140. default: false
  141. },
  142. type: { // 图标类型,1 图片 || 2 图标
  143. type: Number,
  144. default: 1
  145. },
  146. showAlpha: { // 透明度
  147. type: Boolean,
  148. default: false
  149. },
  150. btnStyle: { // 按钮样式 1: 图片加文字 2: 图片 3: text: 文字
  151. type: Number,
  152. default: 1
  153. },
  154. maxIconLength: { // 最多添加数量
  155. type: Number,
  156. default: 0
  157. },
  158. showAddBtn: { // 是否展示添加按钮
  159. type: Boolean,
  160. default: false
  161. },
  162. suggestText: { // 图片建议尺寸
  163. type: String,
  164. default: ''
  165. },
  166. iconSetStyle: { // 按钮列表的样式
  167. type: Object,
  168. default: () => {}
  169. },
  170. imgUrl: { // 添加的列表展示的图片
  171. type: String,
  172. default: ''
  173. },
  174. defaultTabs: {
  175. type: Array,
  176. default: () => ["mall", "addons", "other"]
  177. },
  178. showId: {
  179. type: Boolean,
  180. default: true
  181. }
  182. },
  183. data() {
  184. return {
  185. visible: false,
  186. cardIndex: 0,
  187. is_show_close: false,
  188. iconList: [],
  189. popTitle: '确定删除吗',
  190. showConfrimBtn: true,
  191. urlPop: false,
  192. urlIndex: -1,
  193. }
  194. },
  195. computed: {
  196. set_style() {
  197. return this.btnStyle == 1 ? 'image_text' : this.btnStyle == 2 ? 'image' : 'text'
  198. },
  199. showTitle() {
  200. return this.title ? true : false
  201. }
  202. },
  203. watch: {
  204. list: {
  205. deep:true,
  206. immediate: true,
  207. handler(val) {
  208. console.log(val, '--------')
  209. this.iconList = val
  210. this.changes()
  211. }
  212. }
  213. },
  214. created() {
  215. },
  216. methods: {
  217. updatePop(boo){
  218. console.log(boo)
  219. this.urlPop = !this.urlPop;
  220. },
  221. selectedUrl(e, item) {
  222. let info = e[0]
  223. console.log(info, 'info')
  224. item.link_params = info
  225. this.$forceUpdate()
  226. this.$emit('change', this.iconList)
  227. },
  228. // 图片添加链接
  229. addUrl(index){
  230. this.urlIndex = index;
  231. this.urlPop=true;
  232. },
  233. closeHandle(it, i) {
  234. if (this.iconList.length == 1) {
  235. this.popTitle = '至少保留1个'
  236. this.showConfrimBtn = false
  237. }
  238. this.cardIndex = i
  239. this.visible = true
  240. },
  241. closePop(){
  242. this.visible = false
  243. },
  244. changes() {
  245. this.$emit('change', this.iconList)
  246. },
  247. coverPic(e, item) {
  248. let img = e[0].url
  249. item.img = img
  250. this.changes()
  251. },
  252. delPic(it, i) {
  253. it.img = ''
  254. this.changes()
  255. },
  256. addClick() {
  257. if (this.iconList.length >= this.maxIconLength) {
  258. return;
  259. }
  260. let obj = {
  261. // img: this.dynamicImgSrc(this.imgUrl),
  262. img: this.imgUrl,
  263. icon: 'el-icon-setting',
  264. is_show_tag: false,
  265. tags: '热门',
  266. tagsBgColor: '#f83287',
  267. tagsTextColor: '#ffffff',
  268. btnText: '按钮文字',
  269. link_params: null,
  270. }
  271. this.iconList.push(obj)
  272. console.log(this.iconList, 'hehe')
  273. this.changes()
  274. },
  275. iconSetChange(e, item, name) {
  276. item[name] = e
  277. this.changes()
  278. },
  279. delCards(e, i) {
  280. this.visible = false
  281. this.iconList.splice(i, 1)
  282. this.changes()
  283. }
  284. }
  285. })
  286. </script>
  287. <style>
  288. .icon-set-list-content .com-pick-link-content {
  289. width: 310px;
  290. }
  291. .icon-set-list-content .diy-url {
  292. padding: 9px 15px;
  293. }
  294. .popover-tips {
  295. font-size: 12px;
  296. text-align: center;
  297. padding-bottom: 5px;
  298. }
  299. .icon-set-list {
  300. position: relative;
  301. border-radius: 8px;
  302. background-color: #F4F3F7;
  303. /* padding: 18px 12px; */
  304. padding: 15px 30px 15px 12px;
  305. margin-bottom: 20px;
  306. }
  307. .icon-set-title {
  308. line-height: 1;
  309. color: #47565d;
  310. font-weight: bolder;
  311. margin-bottom: 20px;
  312. }
  313. .icon-set-close {
  314. display: none;
  315. position: absolute;
  316. top: 10px;
  317. right: 0;
  318. width: 30px;
  319. height: 30px;
  320. color: #999;
  321. cursor: pointer;
  322. }
  323. .icon-set-list:hover .icon-set-close {
  324. display: block;
  325. }
  326. .icon-set-items {
  327. margin-bottom: 20px;
  328. }
  329. .icon-set-items:last-child {
  330. margin-bottom: 0;
  331. }
  332. .icon-set-list-name {
  333. width: 60px;
  334. text-align: right;
  335. padding-right: 8px;
  336. margin-right: 15px;
  337. }
  338. .content-upload {
  339. width: 50px;
  340. height: 50px;
  341. border-radius: 8px;
  342. cursor: pointer;
  343. background-color: #E3E3E3;
  344. color: #fff;
  345. }
  346. .content-img {
  347. position: relative;
  348. width: 50px;
  349. height: 50px;
  350. border-radius: 8px;
  351. cursor: pointer;
  352. }
  353. .icon-close {
  354. display: none;
  355. position: absolute;
  356. top: -8px;
  357. left: 35px;
  358. width: 20px;
  359. height: 20px;
  360. border-radius: 50%;
  361. background-color: rgba(0, 0, 0, .3);
  362. color: #fff;
  363. text-align: center;
  364. }
  365. .img-replace {
  366. display: none;
  367. position: absolute;
  368. bottom: 0;
  369. width: 100%;
  370. background-color: rgba(0, 0, 0, .3);
  371. color: #fff;
  372. text-align: center;
  373. font-size: 12px;
  374. padding: 2px 0;
  375. }
  376. .content-img:hover .icon-close,
  377. .content-img:hover .img-replace {
  378. display: block;
  379. }
  380. .icon-set-list-content {
  381. flex: 1;
  382. }
  383. .icon-set-list-content .el-switch__labe {
  384. font-size: 15px;
  385. color: #999999 !important;
  386. font-weight: 700;
  387. padding-left: 5px;
  388. }
  389. .icon-set-items .el-color-picker {
  390. height: auto;
  391. }
  392. .add-btns {
  393. border: 1px dashed #707070;
  394. line-height: 32px;
  395. height: 34px;
  396. border-radius: 5px;
  397. text-align: center;
  398. cursor: pointer;
  399. color: var(--textGray, #999999);
  400. }
  401. .diy-url {
  402. margin-left: 0 !important;
  403. }
  404. </style>