com-topic-detail.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. $diyPath = \Yii::$app->viewPath . '/components/diy';
  3. $currentDir = opendir($diyPath);
  4. $components = [];
  5. while (($file = readdir($currentDir)) !== false) {
  6. if (stripos($file, 'diy-') === 0) {
  7. $components[] = substr($file, 4, (stripos($file, '.php') - 4));
  8. }
  9. }
  10. closedir($currentDir);
  11. foreach ($components as $component) {
  12. Yii::$app->loadComponentView("diy-{$component}", $diyPath);
  13. }
  14. Yii::$app->loadComponentView('com-hotspot');
  15. Yii::$app->loadComponentView('com-rich-text');
  16. $baseUrl = Yii::$app->request->baseUrl;
  17. ?>
  18. <style>
  19. .all-components {
  20. width: 422px;
  21. background: #fff;
  22. }
  23. .all-components .component-group {
  24. width: 422px;
  25. margin-bottom: 20px;
  26. }
  27. .all-components .component-group:last-child {
  28. margin-bottom: 0;
  29. }
  30. .all-components .component-group-name {
  31. height: 35px;
  32. line-height: 35px;
  33. background: #f7f7f7;
  34. padding: 0 20px;
  35. border-bottom: 1px solid #eeeeee;
  36. }
  37. .all-components .component-list {
  38. flex-wrap: wrap;
  39. border: 0 solid #eeeeee;
  40. border-width: 1px 0 0 1px;
  41. }
  42. .all-components .component-list .component-item {
  43. width: 140px;
  44. height: 100px;
  45. border: 0 solid #eeeeee;
  46. border-width: 0 1px 1px 0;
  47. text-align: center;
  48. padding: 15px 0 0;
  49. cursor: pointer;
  50. }
  51. .all-components .component-list .component-icon {
  52. width: 40px;
  53. height: 40px;
  54. /*border: 1px solid #eee;*/
  55. }
  56. .all-components .component-list .component-name {
  57. }
  58. .mobile-framework {
  59. width: 420px;
  60. padding: 22px 22px 22px 23px;
  61. background-color: #FFFFFF;
  62. border-radius: 16px;
  63. }
  64. .mobile-framework-header {
  65. height: 60px;
  66. line-height: 60px;
  67. background: #333;
  68. color: #fff;
  69. text-align: center;
  70. background: url('resources/img/mall/topic-head.png') no-repeat;
  71. border: 0 solid #eeeeee;
  72. border-width: 2px 2px 0 2px;
  73. width: 375px;
  74. }
  75. .mobile-framework-body {
  76. width: 375px;
  77. min-height: 500px;
  78. border: 1px solid #e2e2e2;
  79. background: #f5f7f9;
  80. }
  81. .mobile-framework .diy-component-preview {
  82. cursor: pointer;
  83. position: relative;
  84. zoom: 0.5;
  85. -moz-transform: scale(0.5);
  86. -moz-transform-origin: top left;
  87. font-size: 28px;
  88. }
  89. @-moz-document url-prefix() {
  90. .mobile-framework .diy-component-preview {
  91. cursor: pointer;
  92. position: relative;
  93. -moz-transform: scale(0.5);
  94. -moz-transform-origin: top left;
  95. font-size: 28px;
  96. width: 200% !important;
  97. height: 100%;
  98. margin-bottom: auto;
  99. }
  100. .mobile-framework .active .diy-component-preview {
  101. border: 2px dashed #409EFF;
  102. left: -2px;
  103. right: -2px;
  104. width: calc(200% + 4px) !important;
  105. }
  106. }
  107. .mobile-framework .diy-component-preview:hover {
  108. box-shadow: inset 0 0 10000px rgba(0, 0, 0, .03);
  109. }
  110. .mobile-framework .diy-component-edit {
  111. position: absolute;
  112. top: 0;
  113. bottom: 0;
  114. left: 465px;
  115. right: 0;
  116. background: #fff;
  117. padding: 20px;
  118. display: none;
  119. overflow: auto;
  120. }
  121. .diy-component-options {
  122. position: relative;
  123. }
  124. .diy-component-options .el-button {
  125. height: 22px;
  126. line-height: 22px;
  127. width: 22px;
  128. padding: 0;
  129. text-align: center;
  130. border: none;
  131. border-radius: 0;
  132. position: absolute;
  133. margin-left: 0;
  134. }
  135. .mobile-framework .active .diy-component-preview {
  136. border: 2px dashed #409EFF;
  137. left: -2px;
  138. right: -2px;
  139. width: calc(100% + 4px);
  140. }
  141. .mobile-framework .active .diy-component-edit {
  142. display: block;
  143. padding-right: 20%;
  144. min-width: 650px;
  145. }
  146. .all-components {
  147. max-height: 625px;
  148. overflow-y: auto;
  149. }
  150. .bottom-menu {
  151. text-align: center;
  152. height: 54px;
  153. width: 100%;
  154. }
  155. .bottom-menu .el-card__body {
  156. padding-top: 10px;
  157. }
  158. .el-dialog {
  159. min-width: 800px;
  160. }
  161. </style>
  162. <template id="com-topic-detail" v-cloak>
  163. <div class="com-topic-detail">
  164. <div style="position: relative;margin-bottom: 10px;height: 621px;">
  165. <div class="all-components">
  166. <div class="component-group" v-for="group in allComponents">
  167. <div class="component-list" flex="">
  168. <template v-for="item in group.list">
  169. <div class="component-item" @click="selectComponent(item)">
  170. <img class="component-icon" :src="item.icon">
  171. <div class="component-name">{{item.name}}</div>
  172. </div>
  173. </template>
  174. </div>
  175. </div>
  176. </div>
  177. <div style="width: 430px; overflow-y: auto; overflow-x: hidden;margin-top: 16px;height: 605px;">
  178. <div class="mobile-framework">
  179. <div class="mobile-framework-header"></div>
  180. <div class="mobile-framework-body">
  181. <draggable v-model="components" :options="{filter:'.active',preventOnFilter:false}"
  182. v-if="components && components.length">
  183. <div v-for="(component, index) in components" :key="component.key"
  184. @click="showComponentEdit(component,index)"
  185. :class="(component.active?'active':'')">
  186. <div class="diy-component-options" v-if="component.active">
  187. <el-button type="primary"
  188. icon="el-icon-delete"
  189. @click.stop="deleteComponent(index)"
  190. style="left: -25px;top:0;"></el-button>
  191. <el-button type="primary"
  192. icon="el-icon-document-copy"
  193. @click.stop="copyComponent(index)"
  194. style="left: -25px;top:30px;"></el-button>
  195. <el-button v-if="index > 0 && components.length > 1"
  196. type="primary"
  197. icon="el-icon-arrow-up"
  198. @click.stop="moveUpComponent(index)"
  199. style="right: -25px;top:0;"></el-button>
  200. <el-button v-if="components.length > 1 && index < components.length-1"
  201. type="primary"
  202. icon="el-icon-arrow-down"
  203. @click.stop="moveDownComponent(index)"
  204. style="right: -25px;top:30px;"></el-button>
  205. </div>
  206. <?php foreach ($components as $component) : ?>
  207. <diy-<?= $component ?> v-if="component.id === '<?= $component ?>'"
  208. :active="component.active"
  209. v-model="component.data"></diy-<?= $component ?>>
  210. <?php endforeach; ?>
  211. </div>
  212. </draggable>
  213. <div v-else flex="main:center cross:center"
  214. style="height: 200px;color: #adb1b8;text-align: center;">
  215. <div>
  216. <i class="el-icon-folder-opened"
  217. style="font-size: 32px;margin-bottom: 10px"></i>
  218. <div>空空如也</div>
  219. <div>请从上方组件库添加组件</div>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. </template>
  228. <!-- <script src="//cdnjs.cloudflare.com/ajax/libs/Vue.Draggable/2.18.1/vuedraggable.umd.min.js"></script> -->
  229. <script src="<?= Yii::$app->request->baseUrl ?>/resources/unpkg/vuedraggable@2.18.1/dist/vuedraggable.umd.min.js"></script>
  230. <script>
  231. Vue.component('com-topic-detail', {
  232. template: '#com-topic-detail',
  233. props: {
  234. value: Array,
  235. },
  236. data() {
  237. return {
  238. allComponents: [
  239. {
  240. list: [
  241. {
  242. id: 'rubik',
  243. name: '图片广告',
  244. icon: '<?=$baseUrl?>/resources/img/mall/diy/rubik.png',
  245. },
  246. {
  247. id: 'video',
  248. name: '视频',
  249. icon: '<?=$baseUrl?>/resources/img/mall/diy/video.png',
  250. },
  251. {
  252. id: 'image-text',
  253. name: '图文详情',
  254. icon: '<?=$baseUrl?>/resources/img/mall/diy/image-text.png',
  255. },
  256. ]
  257. }
  258. ],
  259. components: this.value ? this.value : [],
  260. };
  261. },
  262. created() {
  263. if (!this.value) {
  264. } else {
  265. this.components = JSON.parse(JSON.stringify(this.value));
  266. }
  267. },
  268. watch: {
  269. components: {
  270. handler(v) {
  271. let data = [];
  272. for (let i in v) {
  273. data.push({
  274. id: v[i].id,
  275. data: v[i].data
  276. })
  277. }
  278. this.$emit('input', data);
  279. },
  280. immediate: true,
  281. deep: true,
  282. },
  283. },
  284. methods: {
  285. selectComponent(e) {
  286. if (e.single) {
  287. for (let i in this.components) {
  288. if (this.components[i].id === e.id) {
  289. this.$message.error('该组件只允许添加一个。');
  290. return;
  291. }
  292. }
  293. }
  294. let currentIndex = this.components.length;
  295. for (let i in this.components) {
  296. if (this.components[i].active) {
  297. currentIndex = i + 1;
  298. break;
  299. }
  300. }
  301. const component = {
  302. id: e.id,
  303. data: null,
  304. active: false,
  305. key: randomString(),
  306. };
  307. this.components.splice(currentIndex, 0, component);
  308. },
  309. showComponentEdit(component, index) {
  310. for (let i in this.components) {
  311. if (i == index) {
  312. this.components[i].active = true;
  313. } else {
  314. this.components[i].active = false;
  315. }
  316. }
  317. },
  318. deleteComponent(index) {
  319. this.components.splice(index, 1);
  320. },
  321. copyComponent(index) {
  322. for (let i in this.allComponents) {
  323. for (let j in this.allComponents[i].list) {
  324. if (this.allComponents[i].list[j].id === this.components[index].id) {
  325. if (this.allComponents[i].list[j].single) {
  326. this.$message.error('该组件只允许添加一个。');
  327. return;
  328. }
  329. }
  330. }
  331. }
  332. let json = JSON.stringify(this.components[index]);
  333. let copy = JSON.parse(json);
  334. copy.active = false;
  335. copy.key = randomString();
  336. this.components.splice(index + 1, 0, copy);
  337. },
  338. moveUpComponent(index) {
  339. this.swapComponents(index, index - 1);
  340. },
  341. moveDownComponent(index) {
  342. this.swapComponents(index, index + 1);
  343. },
  344. swapComponents(index1, index2) {
  345. this.components[index2] = this.components.splice(index1, 1, this.components[index2])[0];
  346. },
  347. },
  348. });
  349. </script>