index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <div id="app" class="diy-index" v-cloak ref="contain" v-loading="loading">
  2. <div class="nav">店铺装修</div>
  3. <div class="header_box" style="flex: 1;">
  4. <div ref="crad-header" class="add_temp_box flex flex-x-between flex-y-center">
  5. <div class="add_temp_left flex flex-y-center">
  6. <p style="margin-right: 30px;">页面管理</p>
  7. <el-button type="primary" style="width: 162px;height:40px" @click="$navigate({r: 'mall/diy/edit'})">新建页面</el-button>
  8. </div>
  9. <div class="add_temp_right">
  10. <el-input placeholder="输入页面关键词搜索" v-model='title' suffix-icon="el-icon-search" @change='changeName'></el-input>
  11. </div>
  12. </div>
  13. <div style="flex: 1;margin-top:10px">
  14. <el-table :data="temp_list">
  15. <el-table-column prop="id" label="页面ID" width="100"></el-table-column>
  16. <el-table-column prop="title" label="页面名称">
  17. <template slot-scope="scope">
  18. <i v-if="scope.row.is_home_page == 1" class="el-icon-s-home" style="color: #0A54EA;font-size: 16px;"></i>
  19. <i v-if="scope.row.template == 'goods_detail'" class="el-icon-s-goods" style="color: #0A54EA;font-size: 16px;"></i>
  20. <i v-if="scope.row.template == 'user_center'" class="el-icon-user-solid" style="color: #0A54EA;font-size: 16px;"></i>
  21. {{ scope.row.title }}
  22. </template>
  23. </el-table-column>
  24. <el-table-column prop="is_home_page" label="页面类型">
  25. <template slot-scope="scope">
  26. <el-tag v-if="scope.row.template == 'home_page' && scope.row.is_home_page == 1" effect="plain" size="medium" style="margin-right: 5px;"> 首页 </el-tag>
  27. <el-tag v-else effect="plain" :type="scope.row.template == 'custom_page' ? 'info' : ''" size="medium"> {{template[scope.row.template]}} </el-tag>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="created_at" label="创建时间">
  31. <template slot-scope="scope">
  32. <div>{{ scope.row.created_at | dateTimeFormat('Y-m-d H:i')}}</div>
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="操作" width="600">
  36. <template slot-scope="scope">
  37. <el-breadcrumb separator="|">
  38. <el-breadcrumb-item>
  39. <span class="operation" @click="handle('edit', scope.row)">编辑</span>
  40. </el-breadcrumb-item>
  41. <el-breadcrumb-item v-if="isShoeDeletePage(scope.row)">
  42. <span class="operation" @click="handle('destroy', scope.row)">删除</span>
  43. </el-breadcrumb-item>
  44. <el-breadcrumb-item v-if="no_copy_template.indexOf(scope.row.template) == -1">
  45. <span class="operation" @click="handle('copy_page', scope.row)">复制页面</span>
  46. </el-breadcrumb-item>
  47. <el-breadcrumb-item v-if="no_copy_url.indexOf(scope.row.template) == -1">
  48. <span class="operation copy_btn" @click="handle('copy_link', scope.row)">复制链接</span>
  49. </el-breadcrumb-item>
  50. <el-breadcrumb-item v-if="no_copy_url.indexOf(scope.row.template) == -1 && alipay_mini_app_id">
  51. <span class="operation copy_alipay_mini_url_btn" @click="handle('copy_alipay_mini_link', scope.row)">支付宝链接</span>
  52. </el-breadcrumb-item>
  53. <el-breadcrumb-item v-if="no_copy_url.indexOf(scope.row.template) == -1">
  54. <span class="operation" @click="handle('qrcode', scope.row)">二维码</span>
  55. </el-breadcrumb-item>
  56. <el-breadcrumb-item v-if="isShoeSetPage(scope.row)">
  57. <span class="operation" @click="handle('set_home', scope.row)">设为首页</span>
  58. </el-breadcrumb-item>
  59. <el-breadcrumb-item v-if="isShoeSetPage(scope.row)">
  60. <span class="operation" @click="handle('set_show_nav', scope.row)">
  61. {{scope.row.is_show_bottom_nav == 1 ? '隐藏导航' : '显示导航'}}
  62. </span>
  63. </el-breadcrumb-item>
  64. </el-breadcrumb>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. </div>
  69. <div style="text-align: right;margin: 20px 0;" ref="page">
  70. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  71. </div>
  72. </div>
  73. <!-- 二维码 -->
  74. <div id="qrcode-info" style="position: fixed;top: 10000000000px;">
  75. <!-- 二维码 -->
  76. <div id="qrcode" style="width:150px; height:150px;"></div>
  77. </div>
  78. <el-dialog :close-on-click-modal="false" v-loading="posterLoading" element-loading-text="二维码生成中" title="二维码" :visible.sync="sharePop" width="30%">
  79. <el-form ref="shareData" :model="shareData" label-width="80px">
  80. <el-form-item label="">
  81. <el-image style="width: 144px; height: 144px; margin-left: 25%;" :src="shareData.img"></el-image>
  82. </el-form-item>
  83. </el-form>
  84. </el-dialog>
  85. <!--支付宝小程序链接复制-->
  86. <el-dialog :close-on-click-modal="false" title="支付支付宝小程序链接" :visible.sync="copyAlipayMiniDialogVisible" width="50%">
  87. <el-form>
  88. <el-form-item label="页面路径及参数">
  89. <el-input v-model="alipay_path" :disabled="true">
  90. <template #append>
  91. <el-button @click="onCopyAlipayUrl(alipay_path, 'btn-copy-alipay-path')" class="btn-copy-alipay-path">复制</el-button>
  92. </template>
  93. </el-input>
  94. </el-form-item>
  95. <el-form-item label="支付宝小程序URL(参数已转)">
  96. <el-input v-model="alipay_mini_path" :disabled="true">
  97. <template #append>
  98. <el-button @click="onCopyAlipayUrl(alipay_mini_path, 'btn-copy-alipay-mini-path')" class="btn-copy-alipay-mini-path">复制</el-button>
  99. </template>
  100. </el-input>
  101. </el-form-item>
  102. </el-form>
  103. <span slot="footer" class="dialog-footer">
  104. <el-button @click="copyAlipayMiniDialogVisible = false">关 闭</el-button>
  105. </span>
  106. </el-dialog>
  107. </div>
  108. <script src="/resources/unpkg/clipboard@1.5.12/dist/clipboard.min.js"></script>
  109. <script>
  110. new Vue({
  111. el: '#app',
  112. data() {
  113. return {
  114. loading: false,
  115. template: [],
  116. temp_list: [],
  117. title: null,
  118. no_copy_template: ['goods_detail','user_center'],
  119. no_copy_url: ['goods_detail'],
  120. page: 1,
  121. pageCount: 0,
  122. posterLoading: false,
  123. sharePop: false, //分享弹窗
  124. shareData: {
  125. img: ''
  126. },
  127. alipay_mini_app_id: null,
  128. copyAlipayMiniDialogVisible: false,
  129. alipay_path: '',
  130. alipay_mini_path: ''
  131. }
  132. },
  133. watch: {
  134. direction(newVal) { //控制图片随鼠标上下滑动而滑动
  135. if (newVal == 'up') { //分成两个方法为了方便控制上下滚动
  136. clearInterval(this.timerDown)
  137. this.rollingUp();
  138. } else {
  139. clearInterval(this.timerUp)
  140. this.rollingDown();
  141. }
  142. }
  143. },
  144. created() {
  145. this.getList();
  146. },
  147. methods: {
  148. isShoeSetPage(item) {
  149. return item.is_home_page == 0 && (item.template == 'home_page' || item.type == 1)
  150. },
  151. isShoeDeletePage(item) {
  152. return item.is_home_page != 1 && item.type == 1
  153. },
  154. pagination(currentPage) {
  155. let self = this;
  156. self.page = currentPage;
  157. self.getList();
  158. },
  159. handleEdit(index, row) {
  160. console.log(index, row);
  161. },
  162. handleDelete(index, row) {
  163. console.log(index, row);
  164. },
  165. async handle(type, data = null) {
  166. let id = data ? parseInt(data.id) : '';
  167. switch (type) {
  168. case 'edit':
  169. let params = {
  170. r: 'mall/diy/edit'
  171. };
  172. if (id) params = Object.assign(params, {
  173. id: id
  174. });
  175. navigateTo(params);
  176. break;
  177. case 'destroy':
  178. if (data.type == 2) {
  179. this.$message.error('该页面不允许删除!');
  180. return false;
  181. }
  182. param = {
  183. id: data.id
  184. };
  185. this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {
  186. type: 'warning'
  187. }).then(() => {
  188. this.send(param, 'mall/diy/delete')
  189. })
  190. break;
  191. case 'copy_page':
  192. param = {
  193. id: data.id
  194. };
  195. this.send(param, 'mall/diy/copy-page');
  196. break;
  197. case 'set_home':
  198. param = {
  199. id: data.id,
  200. };
  201. this.send(param, 'mall/diy/set-home');
  202. break;
  203. case 'copy_link':
  204. this.copyLink(data);
  205. break;
  206. case 'copy_alipay_mini_link':
  207. this.copyAlipayMiniLink(data);
  208. break;
  209. case 'qrcode':
  210. let codeImgSrc = await this.getQrCode(data.web_url);
  211. this.shareData.img = codeImgSrc;
  212. this.sharePop = true;
  213. break;
  214. case 'set_show_nav':
  215. param = {
  216. id: data.id,
  217. };
  218. this.send(param, 'mall/diy/set-show-nav');
  219. break;
  220. }
  221. },
  222. send(params, url = '') {
  223. let self = this;
  224. request({
  225. params: {
  226. r: url,
  227. },
  228. method: 'post',
  229. data: params
  230. }).then(e => {
  231. if (e.data.code == 0) {
  232. self.$message.success(e.data.msg);
  233. self.getList();
  234. } else {
  235. self.$message.error(e.data.msg);
  236. }
  237. }).catch(e => {
  238. console.log(e);
  239. });
  240. },
  241. copyLink(data) { //复制链接
  242. var clipboard = new ClipboardJS('.copy_btn', {
  243. text: function() {
  244. return data.web_url;
  245. }
  246. });
  247. clipboard.on('success', (e) => {
  248. this.$message.success('复制成功!');
  249. e.clearSelection()
  250. clipboard.destroy()
  251. });
  252. clipboard.on('error', (e) => {
  253. this.$message.error('复制失败!');
  254. this.clipboard.destroy()
  255. });
  256. },
  257. copyAlipayMiniLink(data) { //复制链接
  258. if (isEmpty(data.alipay_mini_link)) {
  259. this.$message.error("请设置商城的H5域名");
  260. return;
  261. }
  262. let paths = data.web_url.split('#')
  263. console.log(paths)
  264. if (paths.length > 1) {
  265. this.alipay_path = `&${paths[1]}`;
  266. } else {
  267. this.alipay_path = data.alipay_mini_link
  268. }
  269. this.alipay_mini_path = data.alipay_mini_link;
  270. this.copyAlipayMiniDialogVisible = true;
  271. },
  272. onCopyAlipayUrl(str, btn) {
  273. let clipboard = new ClipboardJS(`.${btn}`, {
  274. text: function() {
  275. return str;
  276. }
  277. });
  278. clipboard.on('success', (e) => {
  279. this.$message.success('复制成功!');
  280. e.clearSelection()
  281. clipboard.destroy()
  282. });
  283. clipboard.on('error', (e) => {
  284. this.$message.error('复制失败!');
  285. this.clipboard.destroy()
  286. });
  287. },
  288. changeName(e) {
  289. this.title = e;
  290. this.getList();
  291. },
  292. getList() {
  293. this.loading = true;
  294. this.$request({
  295. params: {
  296. r: 'mall/diy/index',
  297. title: this.title,
  298. page: this.page
  299. },
  300. method: 'get',
  301. }).then(e => {
  302. this.loading = false;
  303. if (e.data.code == 0) {
  304. this.temp_list = e.data.data.list;
  305. this.template = e.data.data.template;
  306. this.pageCount = e.data.data.page_count;
  307. this.alipay_mini_app_id = e.data.data.alipay_mini_app_id
  308. }
  309. });
  310. },
  311. handleClose(done) {
  312. this.dialogVisible = false;
  313. clearInterval(this.timerUp);
  314. clearInterval(this.timerDown);
  315. this.scrolltop = 0;
  316. this.$refs.uContent.scrollTop = 0;
  317. },
  318. enterImg() { //进入图片事件
  319. setTimeout(() => { //加一个延时,防止鼠标刚移进去图片就开始动
  320. this.is_begin = true;
  321. }, 1000)
  322. },
  323. imgMove(e) { //图片滚动事件
  324. if (!this.is_begin) return;
  325. if (this.clientY != 0) {
  326. if (this.clientY > e.clientY) {
  327. this.direction = 'up';
  328. } else {
  329. this.direction = 'down';
  330. }
  331. };
  332. this.clientY = e.clientY;
  333. },
  334. rollingDown() {
  335. this.timerDown = setInterval(() => {
  336. if (this.$refs.uContent.scrollHeight - 696 >= this.scrolltop) {
  337. this.scrolltop = this.scrolltop + this.speed;
  338. this.$refs.uContent.scrollTop = this.scrolltop;
  339. } else {
  340. clearInterval(this.timerDown);
  341. }
  342. }, 2)
  343. },
  344. rollingUp() {
  345. this.timerUp = setInterval(() => {
  346. if (this.$refs.uContent.scrollTop <= 0) {
  347. clearInterval(this.timerUp);
  348. } else {
  349. this.scrolltop = this.scrolltop - this.speed;
  350. this.$refs.uContent.scrollTop = this.scrolltop;
  351. }
  352. }, 2)
  353. },
  354. // 生成二维码
  355. getQrCode(url) {
  356. let qrcodeInfo = document.getElementById("qrcode-info");
  357. document.getElementById("qrcode").remove(); //删除生成的二维码
  358. let addCodeDom = document.createElement("div")
  359. addCodeDom.setAttribute("id", "qrcode");
  360. addCodeDom.setAttribute("style", "width:300px; height:300px;");
  361. qrcodeInfo.appendChild(addCodeDom) //添加标签
  362. let qrCodeDom = document.getElementById("qrcode")
  363. var qrcode = new QRCode(qrCodeDom, {
  364. width: 300,
  365. height: 300
  366. });
  367. qrcode.makeCode(url);
  368. // 获取二维码生成的图片信息
  369. let src = "";
  370. return new Promise((req, rej) => {
  371. setTimeout(() => {
  372. src = qrCodeDom.getElementsByTagName("img")[0].src;
  373. req(src)
  374. }, 200);
  375. })
  376. },
  377. }
  378. })
  379. </script>
  380. <style scoped>
  381. .nav {
  382. background: #ffffff;
  383. border-radius: 5px;
  384. padding: 26px 24px;
  385. margin-bottom: 10px;
  386. }
  387. .diy-index {
  388. display: flex;
  389. flex-direction: column;
  390. }
  391. .header_box {
  392. display: flex;
  393. flex-direction: column;
  394. padding: 25px;
  395. background: #fff;
  396. border-radius: 5px 5px 0 0;
  397. color: #808695;
  398. }
  399. .add_temp_right {
  400. width: 400px;
  401. }
  402. .operation {
  403. cursor: pointer;
  404. color: #409eff;
  405. }
  406. .operation:hover {
  407. color: #fb6638;
  408. }
  409. /* 公共样式 */
  410. .flex {
  411. display: -webkit-box;
  412. display: -webkit-flex;
  413. /* #ifndef APP-NVUE */
  414. display: flex;
  415. /* #endif */
  416. }
  417. .flex-x-center {
  418. display: -webkit-box;
  419. display: -webkit-flex;
  420. /* #ifndef APP-NVUE */
  421. display: flex;
  422. /* #endif */
  423. -webkit-box-pack: center;
  424. -webkit-justify-content: center;
  425. -ms-flex-pack: center;
  426. justify-content: center;
  427. }
  428. .flex-x-between {
  429. display: -webkit-box;
  430. display: -webkit-flex;
  431. /* #ifndef APP-NVUE */
  432. display: flex;
  433. /* #endif */
  434. -webkit-box-pack: space-between;
  435. -webkit-justify-content: space-between;
  436. -ms-flex-pack: space-between;
  437. justify-content: space-between;
  438. }
  439. .flex-y-center {
  440. display: -webkit-box;
  441. display: -webkit-flex;
  442. /* #ifndef APP-NVUE */
  443. display: flex;
  444. /* #endif */
  445. -webkit-box-align: center;
  446. -webkit-align-items: center;
  447. -ms-flex-align: center;
  448. -ms-grid-row-align: center;
  449. align-items: center;
  450. }
  451. /* 溢出隐藏 */
  452. .over1 {
  453. text-overflow: -o-ellipsis-lastline;
  454. overflow: hidden;
  455. text-overflow: ellipsis;
  456. display: -webkit-box;
  457. -webkit-line-clamp: 1;
  458. -webkit-box-orient: vertical;
  459. }
  460. .el-card {
  461. background: transparent;
  462. box-shadow: none !important;
  463. border: 0;
  464. }
  465. .el-card__body {
  466. padding: 0;
  467. }
  468. .el-table td,
  469. .el-table th {
  470. padding: 12px 0
  471. }
  472. </style>