多租户商城-商户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
6.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="canvas">
  3. <div class="topBox">
  4. <!--<a class="btn-black">返回店铺</a>-->
  5. <ul>
  6. <li v-for="(item,index) in deviceList" :key="index" @click="toggleDevice(item.id)" :class="{'on':terminal == item.id}">
  7. <i class="iconfont" :class="'icon-' + item.name"></i>
  8. </li>
  9. </ul>
  10. <el-button class="btn-save" type="primary" @click="canvasSave">保存画布</el-button>
  11. </div>
  12. <div class="bottomWarp">
  13. <div class="leftBox">
  14. <left-bar></left-bar>
  15. </div>
  16. <div class="mainContentWarp">
  17. <div class="mainContent" :class="'view-' + terminal">
  18. <cereshop-layout :terminal="terminal" :typeId="typeId" :shopId="shopId" @showRightBox="showRightBox"></cereshop-layout>
  19. </div>
  20. </div>
  21. <div class="RightBox">
  22. <tool-panel v-if="comChoose"></tool-panel>
  23. <div v-else class="noChoose">
  24. <div> <i class="iconfont icon-kong"></i><p>没有选定的组件<br>请拖拽左侧组件栏添加或者选择一个组件</p></div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import leftBar from '../components/leftBar/panel.vue'
  32. import toolPanel from '../components/toolBar/toolPanel'
  33. import CereshopLayout from '../components/canvasEditPage'
  34. import { mapGetters, mapMutations } from 'vuex'
  35. import api from '@@/components/canvasShow/config/api'
  36. import {sendReqMixin} from '@@/components/canvasShow/config/mixin'
  37. import {getShopId, initShopId} from "@@/utils/auth.js"
  38. import Cookies from 'js-cookie'
  39. export default {
  40. name: 'canvasContainer',
  41. mixins: [sendReqMixin],
  42. components: {
  43. CereshopLayout,
  44. leftBar,
  45. toolPanel
  46. },
  47. data () {
  48. return {
  49. comChoose: false,
  50. deviceList: [{
  51. id: 1,
  52. name: 'xiaochengxu'
  53. }, {
  54. id: 2,
  55. name: 'h5'
  56. }, {
  57. id: 4,
  58. name: 'pc'
  59. }, {
  60. id: 3,
  61. name: 'app'
  62. }],
  63. canvasId: '',
  64. shopId: 0
  65. }
  66. },
  67. computed: {
  68. ...mapGetters([
  69. 'terminal',
  70. 'componentsData',
  71. 'typeId'
  72. ])
  73. },
  74. mounted () {
  75. initShopId()
  76. this.shopId = parseInt(getShopId())
  77. if(this.shopId && this.shopId > 0 ){
  78. this.setTypeId(3)
  79. }else{
  80. this.setTypeId(1)
  81. }
  82. this.canvasGet()
  83. },
  84. methods: {
  85. ...mapMutations({
  86. setTerminal: 'SET_TERMINAL',
  87. setTypeId: 'SET_TYPEID',
  88. setActiveComponent: 'SET_ACTIVECOMPONENT',
  89. setComponentsData: 'SET_COMPONENTSDATA'
  90. }),
  91. toggleDevice (id) {
  92. this.setActiveComponent({})
  93. this.setTerminal(id)
  94. this.canvasGet()
  95. },
  96. // 保存画布
  97. canvasSave () {
  98. // 删除非必要的字符
  99. let cloneComponentsData = JSON.parse(JSON.stringify(this.componentsData))
  100. for (let i = 0; i < cloneComponentsData.length; i++) {
  101. delete cloneComponentsData[i].iconClass
  102. if (cloneComponentsData[i].type === 'productList') {
  103. cloneComponentsData[i].componentContent.productData.imgTextData = [] // 清除展示数据
  104. }
  105. }
  106. var paramsData = {
  107. terminal: this.terminal,
  108. json: JSON.stringify(cloneComponentsData)
  109. }
  110. if (this.canvasId) {
  111. paramsData.canvasId = this.canvasId
  112. }
  113. if (this.shopId && this.typeId == 3) {
  114. paramsData.shopId = this.shopId
  115. }
  116. paramsData.type = this.typeId
  117. console.log(paramsData)
  118. let params = {
  119. url: api.saveCanvas,
  120. method: 'POST',
  121. data: paramsData
  122. }
  123. this.sendReq(params, (res) => {
  124. if (res.message) {
  125. this.$message.error(res.message)
  126. } else {
  127. this.$message({
  128. message: '保存成功!',
  129. type: 'success'
  130. })
  131. }
  132. })
  133. },
  134. // 读取画布
  135. canvasGet () {
  136. var _this = this
  137. this.setComponentsData([])
  138. var apiUrl = api.getCanvas + '?terminal=' + this.terminal + '&type=' + this.typeId
  139. if (this.shopId && this.typeId == 3) {
  140. apiUrl += '&shopId=' + this.shopId
  141. }
  142. let params = {
  143. url: apiUrl,
  144. method: 'GET'
  145. }
  146. this.sendReq(params, (res) => {
  147. if(typeof(uni) !== 'undefined'){
  148. uni.setStorage({key: 'sendNum',data: 0});
  149. } else {
  150. localStorage.setItem('sendNum', 0)
  151. }
  152. if (JSON.stringify(res.data) !== '{}') {
  153. _this.canvasId = res.data.canvasId
  154. var componentsData = JSON.parse(res.data.json)
  155. for (let i = 0; i < componentsData.length; i++) {
  156. componentsData[i].componentContent.hasDatas = true
  157. }
  158. _this.setComponentsData(componentsData)
  159. } else {
  160. _this.canvasId = ''
  161. }
  162. },(err)=>{
  163. })
  164. },
  165. // 右侧工具栏显隐
  166. showRightBox (flag) {
  167. this.comChoose = flag
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .canvas {
  174. position: relative;
  175. display: flex;
  176. flex-direction: column;
  177. height: 100%;
  178. .topBox{
  179. height: 52px;
  180. line-height: 52px;
  181. border-bottom: 1px solid #F0F3F4;
  182. position: relative;
  183. display: flex;
  184. justify-content: center;
  185. .btn-black{
  186. position: absolute;
  187. left: 20px;
  188. top: 0;
  189. }
  190. li{
  191. width: 56px;
  192. height: 52px;
  193. cursor: pointer;
  194. text-align: center;
  195. display: inline-block;
  196. .iconfont{
  197. font-size: 24px;
  198. }
  199. &:hover,&.on{
  200. background-color: $mainColor;
  201. color: #fff;
  202. }
  203. }
  204. .btn-save{
  205. position: absolute;
  206. right: 20px;
  207. top: 5px;
  208. }
  209. }
  210. .bottomWarp{
  211. flex: 1;
  212. display: flex;
  213. height: 0;
  214. }
  215. .leftBox {
  216. height: 100%;
  217. overflow-y: auto;
  218. overflow-x: hidden;
  219. }
  220. .mainContentWarp{
  221. background-color: #F0F3F4;
  222. overflow: auto;
  223. height: 100%;
  224. flex: 1;
  225. .mainContent{
  226. margin: 0 auto;
  227. max-width: 100%;
  228. width: 750px;
  229. &.view-4{
  230. width: 1300px;
  231. }
  232. }
  233. }
  234. .RightBox {
  235. height: 100%;
  236. overflow: auto;
  237. .noChoose{
  238. width: 320px;
  239. display: flex;
  240. height: 100%;
  241. -webkit-box-align: center;
  242. align-items: center;
  243. -webkit-box-pack: center;
  244. justify-content: center;
  245. color: #999;
  246. text-align: center;
  247. font-size: 16px;
  248. line-height: 1.8;
  249. .iconfont{
  250. font-size: 100px;
  251. color: $mainColor;
  252. }
  253. }
  254. }
  255. }
  256. </style>