categoryTool.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="categoryTool">
  3. <h3 class="toolTit">类别列表</h3>
  4. <div class="toolBox">
  5. <div class="itemBox">
  6. <label>标题</label>
  7. <el-input v-model="activeComponent.componentContent.title" maxlength="20" placeholder="请输入内容"></el-input>
  8. </div>
  9. <tool-select :linkValue.sync='activeComponent.componentContent.textAlign' title="文字对齐方式" :options="alignList"></tool-select>
  10. <div class="textTit">添加类别</div>
  11. <div class="categoryListBox">
  12. <draggable v-model="activeComponent.componentContent.categoryData">
  13. <div v-for="(item, index) in activeComponent.componentContent.categoryData" :key="index" class="item">
  14. <div class="listItemBox">
  15. <div class="addImgTit" @click="openAddCategory(item, index)">
  16. <div class="titLeft">
  17. <span class="iconfont">&#xe703;</span>
  18. <span class="iconfont">&#xe64a;</span>
  19. <span>类别</span>
  20. </div>
  21. <div class="titRight">
  22. <span class="iconfont" @click.stop="deleteItem(item, index)">&#xe633;</span>
  23. <span v-html="categoryCurrent === index ? '&#xe660;' : '&#xe695;'" class="iconfont"></span>
  24. </div>
  25. </div>
  26. <div class="addBox" v-show="categoryCurrent === index">
  27. <div class="addContent">
  28. <tool-single-img :imageUrl.sync='item.img' tip='建议尺寸5:4等比例图片'></tool-single-img>
  29. <div v-if="!item.selClassData.categoryName" class="addCategoryBox" @click="addItemCategory(item, index)"><span class="iconfont">&#xe685;</span>添加类别</div>
  30. <div v-else class="categoryName">
  31. <span>{{item.selClassData.categoryName}}</span>
  32. <div class="operation">
  33. <span class="iconfont" @click="replaceCategory(index)">&#xe66c;</span>
  34. <span class="iconfont" @click="deleteCategory(index)">&#xe633;</span>
  35. </div>
  36. </div>
  37. </div>
  38. <div @click="deleteItem(item, index)" class="deleteItem"><span class="iconfont">&#xe633;</span>删除内容</div>
  39. </div>
  40. </div>
  41. </div>
  42. </draggable>
  43. </div>
  44. </div>
  45. <div class="addImgBtn" v-show="activeComponent.componentContent.categoryData.length < 6" @click="addCategory"><span class="iconfont">&#xe64a;</span>添加类别</div>
  46. <div class="addImgBtn" v-show="activeComponent.componentContent.categoryData.length === 6"><span class="iconfont">&#xe608;</span>最多只能添加6个</div>
  47. <el-dialog
  48. title="提示"
  49. :visible.sync="dialogVisible"
  50. width="30%"
  51. :before-close="deleteItem">
  52. <span>点击确定删除此项</span>
  53. <span slot="footer" class="dialog-footer">
  54. <el-button @click="dialogVisible = false">取 消</el-button>
  55. <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  56. </span>
  57. </el-dialog>
  58. <el-dialog title="选择类别" :visible.sync="dialogCategory" width="480px">
  59. <category-select ref="categorySelect"></category-select>
  60. <span slot="footer" class="dialog-footer">
  61. <el-button @click="dialogCategory = false">取 消</el-button>
  62. <el-button type="primary" @click="categoryChanged">确 定</el-button>
  63. </span>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script>
  68. import Draggable from 'vuedraggable'
  69. import {toolMixin} from '@@/config/mixin'
  70. import CategorySelect from '../toolModule/category-select'
  71. import ToolSingleImg from '../toolModule/tool-single-img'
  72. import ToolSelect from '../toolModule/tool-select'
  73. // import imageSrc from '../../../assets/canvasImg'
  74. export default {
  75. mixins: [toolMixin],
  76. name: 'categoryTool',
  77. components: {
  78. ToolSelect,
  79. ToolSingleImg,
  80. CategorySelect,
  81. Draggable
  82. },
  83. data () {
  84. return {
  85. title: '', // 标题内容
  86. alignList: [
  87. {
  88. id: 1,
  89. label: '居左',
  90. value: 'left'
  91. },
  92. {
  93. id: 2,
  94. label: '居中',
  95. value: 'center'
  96. },
  97. {
  98. id: 3,
  99. label: '居右',
  100. value: 'right'
  101. }
  102. ],
  103. textAlign: 'left',
  104. categoryCurrent: null,
  105. dialogVisible: false,
  106. dialogCategory: false,
  107. currentCategory: null
  108. }
  109. },
  110. computed: {
  111. },
  112. methods: {
  113. openAddCategory (item, index) {
  114. if (this.categoryCurrent === index) {
  115. this.categoryCurrent = null
  116. return false
  117. }
  118. this.categoryCurrent = index
  119. },
  120. // 添加类别
  121. addCategory () {
  122. this.activeComponent.componentContent.categoryData.push({
  123. selClassData: [],
  124. img: ''
  125. })
  126. },
  127. // 删除内容
  128. deleteItem (item, index) {
  129. this.$confirm('确定删除此项?')
  130. .then(_ => {
  131. this.activeComponent.componentContent.categoryData.splice(index, 1)
  132. })
  133. .catch(_ => {
  134. })
  135. },
  136. addItemCategory (item, index) {
  137. this.dialogCategory = true
  138. this.categoryCurrent = index
  139. },
  140. // 替换类别
  141. replaceCategory (index) {
  142. this.dialogCategory = true
  143. this.categoryCurrent = index
  144. console.log(this.categoryCurrent)
  145. },
  146. // 删除已选类别
  147. deleteCategory (index) {
  148. this.activeComponent.componentContent.categoryData[index].selClassData = ''
  149. },
  150. // 选择类别
  151. categoryChanged () {
  152. let nodesObj = this.$refs.categorySelect.$refs['cascader'].getCheckedNodes()
  153. console.log(nodesObj, this.categoryCurrent)
  154. if (nodesObj) {
  155. var data = nodesObj[0].data
  156. this.dialogCategory = false
  157. this.activeComponent.componentContent.categoryData[this.categoryCurrent].id = data.id
  158. this.activeComponent.componentContent.categoryData[this.categoryCurrent].selClassData = data
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .categoryTool {
  166. padding: 20px 20px 0 20px;
  167. h3 {
  168. font-size: 18px;
  169. font-weight: 500;
  170. height: 35px;
  171. line-height: 35px;
  172. color: #333333;
  173. margin-bottom: 20px;
  174. }
  175. .toolBox {
  176. padding-bottom: 10px;
  177. .textTit {
  178. height: 35px;
  179. line-height: 35px;
  180. font-size: 16px;
  181. color: #333333;
  182. font-weight: bold;
  183. }
  184. .itemBox {
  185. label {
  186. font-size: 14px;
  187. color: #666666;
  188. height: 40px;
  189. line-height: 40px;
  190. }
  191. margin-bottom: 15px;
  192. }
  193. }
  194. ::v-deep .ql-container {
  195. height: 200px;
  196. }
  197. .categoryListBox {
  198. margin-top: 30px;
  199. .item {
  200. border: 1px solid #E8EAEC;
  201. border-radius: 4px;
  202. margin-bottom: 10px;
  203. }
  204. .listItemBox {
  205. .addImgTit {
  206. padding: 10px;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. background: #F6F7F9;
  211. cursor: pointer;
  212. .titLeft {
  213. display: flex;
  214. align-items: center;
  215. span {
  216. color: #7D7E80;
  217. }
  218. span:nth-child(1) {
  219. font-size: 28px;
  220. }
  221. span:nth-child(2) {
  222. font-size: 25px;
  223. margin: 0 6px;
  224. }
  225. span:nth-child(3) {
  226. font-size: 14px;
  227. }
  228. }
  229. .titRight {
  230. display: flex;
  231. align-items: center;
  232. span:nth-child(1) {
  233. width: 40px;
  234. text-align: center;
  235. display: block;
  236. height: 30px;
  237. line-height: 30px;
  238. }
  239. }
  240. }
  241. .addContent {
  242. padding: 13px;
  243. .addCategoryBox {
  244. width: 100%;
  245. height: 35px;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. color: #ffffff;
  250. background: $mainColor;
  251. border-radius: 4px;
  252. margin: 15px 0;
  253. cursor: pointer;
  254. }
  255. .deleteItem {
  256. border-radius: 4px;
  257. background: $mainColor;
  258. text-align: center;
  259. height: 36px;
  260. color: #ffffff;
  261. font-size: 14px;
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. cursor: pointer;
  266. margin-bottom: 10px;
  267. span {
  268. font-size: 18px;
  269. color: #ffffff;
  270. margin-right: 5px;
  271. }
  272. }
  273. .categoryName {
  274. height: 35px;
  275. display: flex;
  276. align-items: center;
  277. background: #e9e9e9;
  278. padding: 0 10px;
  279. justify-content: space-between;
  280. span {
  281. color: #333333;
  282. }
  283. span {
  284. color: #333333;
  285. }
  286. .operation {
  287. display: flex;
  288. span {
  289. width: 35px;
  290. display: block;
  291. height: 35px;
  292. line-height: 35px;
  293. text-align: center;
  294. cursor: pointer;
  295. }
  296. }
  297. }
  298. }
  299. .deleteItem {
  300. padding: 10px;
  301. display: flex;
  302. align-items: center;
  303. justify-content: center;
  304. background: #F6F7F9;
  305. cursor: pointer;
  306. color: $mainColor;
  307. font-size: 14px;
  308. span {
  309. font-size: 16px;
  310. margin-right: 5px;
  311. }
  312. }
  313. }
  314. }
  315. .addImgBtn {
  316. border-radius: 4px;
  317. background: $mainColor;
  318. text-align: center;
  319. height: 36px;
  320. color: #ffffff;
  321. font-size: 14px;
  322. display: flex;
  323. align-items: center;
  324. justify-content: center;
  325. cursor: pointer;
  326. span {
  327. font-size: 20px;
  328. margin-right: 5px;
  329. }
  330. }
  331. .classList {
  332. .classTit {
  333. display: flex;
  334. justify-content: space-between;
  335. height: 50px;
  336. align-items: center;
  337. padding:0 20px;
  338. background: #eeeeee;
  339. span {
  340. display: block;
  341. width: 100px;
  342. text-align: center;
  343. }
  344. }
  345. .classListBox {
  346. max-height: 300px;
  347. overflow-y: auto;
  348. .classItemBox {
  349. display: flex;
  350. padding: 0 20px;
  351. align-items: center;
  352. border-bottom: 1px solid #eeeeee;
  353. div {
  354. display: flex;
  355. flex: 1;
  356. justify-content: space-between;
  357. height: 50px;
  358. align-items: center;
  359. span:nth-child(1) {
  360. padding-left: 5px;
  361. }
  362. span {
  363. display: block;
  364. width: 100px;
  365. text-align: left;
  366. }
  367. span:nth-child(2) {
  368. text-align: center;
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }
  375. </style>