index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <template>
  2. <view class="container">
  3. <!-- 轮播图 start -->
  4. <view class="swiper-wrap">
  5. <swiper class="top-swiper" autoplay="true" duration="400" interval="5000" @change="swiperChange"
  6. indicator-dots indicator-active-color="#fff" indicator-color="rgba(255,255,255,0.8)">
  7. <swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
  8. @click="bannerNavToUrl(item.url)">
  9. <image :src="item.pic" />
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <!-- 轮播图 end -->
  14. <!-- 工具箱 start -->
  15. <view class="tool-box flex">
  16. <view class="tool-item" @click="navto('/pages/user/myjslis')">
  17. <image src="../../static/img/t1.png" mode="widthFix"></image>
  18. </view>
  19. <button open-type="contact" class="tool-item" plain="true">
  20. <image src="../../static/img/t2.png" mode="widthFix"></image>
  21. </button>
  22. <view class="tool-item" @click="navto('/pages/index/zngs?type=0')">
  23. <image src="../../static/img/t4.png" mode="widthFix"></image>
  24. </view>
  25. <view class="tool-item" @click="navto('/pages/index/zngs?type=1')">
  26. <image src="../../static/img/t3.png" mode="widthFix"></image>
  27. </view>
  28. </view>
  29. <!-- 工具箱 end -->
  30. <!-- tip start -->
  31. <!-- <view class="tip">
  32. <image src="../../static/img/tip.png" mode="widthFix"></image>
  33. <view class="tip-tit">
  34. <view class="">
  35. 系统使用说明
  36. </view>
  37. <view class="tit-tit">
  38. 计算系统使用教程小贴士
  39. </view>
  40. </view>
  41. </view> -->
  42. <image src="../../static/img/gbc.png" mode="widthFix" class="gcb"></image>
  43. <view class="" style="height: 47rpx;">
  44. </view>
  45. <!-- tip end -->
  46. <!-- 客服 start -->
  47. <uni-popup ref="popupkf" type="center">
  48. <view class="popup-box">
  49. <view class="img">
  50. <image src="../../static/img/img009.png" mode=""></image>
  51. </view>
  52. <view class="mian">
  53. <view class="delivery">
  54. <view class="title">已经为您定制专属客服</view>
  55. <image src="../../static/img/img010.png" mode=""></image>
  56. </view>
  57. <view class="nocancel">客服VX:{{ text }}</view>
  58. <view class="comfirm-box">
  59. <view class="cancel" @click="cancel">取消</view>
  60. <view class="comfirm" @click="comfirm(text)">复制微信</view>
  61. </view>
  62. </view>
  63. </view>
  64. </uni-popup>
  65. <!-- 客服 end -->
  66. </view>
  67. </template>
  68. <script>
  69. import {
  70. saveUrl,
  71. interceptor
  72. } from '@/utils/loginUtils.js';
  73. import {
  74. loadIndexs
  75. } from '@/api/index.js';
  76. import {
  77. getUserInfo
  78. } from '@/api/user.js';
  79. import {
  80. mapState
  81. } from 'vuex';
  82. export default {
  83. data() {
  84. return {
  85. shareShow: false, //分享海报
  86. pageProportion: 0, //保存页面基于750宽度的比例
  87. swiperHeight: 0,
  88. checkid: 0,
  89. titleNViewBackground: '',
  90. swiperCurrent: 0,
  91. swiperLength: 0,
  92. carouselList: [], //轮播列表
  93. page: 1,
  94. limit: 5,
  95. text: ''
  96. };
  97. },
  98. computed: {
  99. ...mapState(['loginInterceptor']),
  100. ...mapState('user', ['hasLogin', 'userInfo'])
  101. },
  102. onLoad: function(option) {
  103. // #ifndef MP
  104. if (option.spread) {
  105. // 存储其他邀请人
  106. uni.setStorageSync('spread', option.spread);
  107. }
  108. // #endif
  109. // #ifdef MP
  110. if (option.scene) {
  111. // 存储小程序邀请人
  112. uni.setStorage({
  113. key: 'spread_code',
  114. data: option.scene
  115. });
  116. }
  117. // #endif
  118. },
  119. onShow: function() {
  120. // 判断是否强制登录
  121. if (this.loginInterceptor && !this.hasLogin) {
  122. // 登录拦截
  123. interceptor();
  124. }
  125. this.loadData();
  126. },
  127. //下拉刷新
  128. onPullDownRefresh() {
  129. this.loadData();
  130. },
  131. onShareAppMessage(options) {
  132. // 设置菜单中的转发按钮触发转发事件时的转发内容
  133. let pages = getCurrentPages(); //获取加载的页面
  134. let currentPage = pages[pages.length - 1]; //获取当前页面的对象
  135. let url = currentPage.route; //当前页面url
  136. let item = currentPage.options; //如果要获取url中所带的参数可以查看options
  137. let shareObj = {
  138. title: '水箱计算', // 默认是小程序的名称(可以写slogan等)
  139. path: url, // 默认是当前页面,必须是以‘/’开头的完整路径
  140. imageUrl: '',
  141. success: function(res) {
  142. // 转发成功之后的回调
  143. if (res.errMsg == 'shareAppMessage:ok') {}
  144. },
  145. fail: function() {
  146. // 转发失败之后的回调
  147. if (res.errMsg == 'shareAppMessage:fail cancel') {
  148. // 用户取消转发
  149. } else if (res.errMsg == 'shareAppMessage:fail') {
  150. // 转发失败,其中 detail message 为详细失败信息
  151. }
  152. }
  153. };
  154. return shareObj;
  155. },
  156. methods: {
  157. // 打开客服
  158. openKf() {
  159. this.$refs.popupkf.open();
  160. },
  161. // 关闭客服
  162. cancel() {
  163. this.$refs.popupkf.close();
  164. },
  165. navto(url) {
  166. if (!this.hasLogin) {
  167. // 保存地址
  168. saveUrl();
  169. // 登录拦截
  170. interceptor();
  171. } else {
  172. uni.navigateTo({
  173. url,
  174. fail() {
  175. uni.switchTab({
  176. url
  177. })
  178. }
  179. });
  180. }
  181. },
  182. swiperChange() {
  183. },
  184. bannerNavToUrl(url) {
  185. uni.navigateTo({
  186. url,
  187. fail() {
  188. uni.switchTab({
  189. url
  190. })
  191. }
  192. })
  193. },
  194. // 请求载入数据
  195. async loadData() {
  196. loadIndexs({})
  197. .then(({
  198. data
  199. }) => {
  200. let goods = data.info;
  201. this.carouselList = data.banner;
  202. this.swiperLength = this.carouselList.length;
  203. uni.stopPullDownRefresh();
  204. })
  205. .catch(e => {
  206. uni.stopPullDownRefresh();
  207. });
  208. },
  209. // 复制客服微信
  210. comfirm(text) {
  211. console.log(text);
  212. const result = this.uniCopy(text);
  213. if (result === false) {
  214. uni.showToast({
  215. title: '不支持'
  216. });
  217. } else {
  218. uni.showToast({
  219. title: '复制成功',
  220. icon: 'none'
  221. });
  222. }
  223. this.$refs.popupkf.close();
  224. },
  225. uniCopy(content) {
  226. /**
  227. * 小程序端 和 app端的复制逻辑
  228. */
  229. //#ifndef H5
  230. uni.setClipboardData({
  231. data: content,
  232. success: function() {
  233. console.log('success');
  234. return true;
  235. }
  236. });
  237. //#endif
  238. /**
  239. * H5端的复制逻辑
  240. */
  241. // #ifdef H5
  242. if (!document.queryCommandSupported('copy')) {
  243. //为了兼容有些浏览器 queryCommandSupported 的判断
  244. // 不支持
  245. return false;
  246. }
  247. let textarea = document.createElement('textarea');
  248. textarea.value = content;
  249. textarea.readOnly = 'readOnly';
  250. document.body.appendChild(textarea);
  251. textarea.select(); // 选择对象
  252. textarea.setSelectionRange(0, content.length); //核心
  253. let result = document.execCommand('copy'); // 执行浏览器复制命令
  254. textarea.remove();
  255. return result;
  256. // #endif
  257. },
  258. }
  259. };
  260. </script>
  261. <style lang="scss">
  262. // 顶部轮播图
  263. .swiper-wrap {
  264. width: 750rpx;
  265. .top-swiper {
  266. width: 750rpx;
  267. height: 375rpx;
  268. margin: auto;
  269. image {
  270. width: 750rpx;
  271. height: 375rpx;
  272. }
  273. }
  274. }
  275. // 工具箱
  276. .tool-box {
  277. width: 700rpx;
  278. margin: 20rpx auto 5rpx;
  279. justify-content: space-between;
  280. flex-wrap: wrap;
  281. font-size: 0;
  282. .tool-item {
  283. padding: 0;
  284. margin: 0;
  285. width: 344rpx;
  286. height: 180rpx;
  287. border: none;
  288. display: inline-block;
  289. margin-bottom: 15rpx;
  290. image {
  291. width: 344rpx;
  292. }
  293. }
  294. }
  295. .tip {
  296. width: 702rpx;
  297. height: 164rpx;
  298. position: relative;
  299. margin: auto;
  300. image {
  301. width: 702rpx;
  302. }
  303. .tip-tit {
  304. height: 164rpx;
  305. position: absolute;
  306. top: 0;
  307. font-size: 32rpx;
  308. font-weight: bold;
  309. color: #333333;
  310. display: flex;
  311. justify-content: center;
  312. flex-direction: column;
  313. padding-left: 140rpx;
  314. .tit-tit {
  315. margin-top: 15rpx;
  316. font-size: 20rpx;
  317. font-weight: 500;
  318. color: #666666;
  319. }
  320. }
  321. }
  322. .popup-box {
  323. width: 522rpx;
  324. height: 605rpx;
  325. background-color: #ffffff;
  326. border-radius: 20rpx;
  327. position: relative;
  328. .img {
  329. position: relative;
  330. top: -56rpx;
  331. left: 0;
  332. width: 522rpx;
  333. height: 132rpx;
  334. display: flex;
  335. justify-content: center;
  336. image {
  337. border-radius: 20rpx 20rpx 0 0;
  338. width: 450rpx;
  339. height: 132rpx;
  340. }
  341. }
  342. .mian {
  343. margin-top: -44rpx;
  344. display: flex;
  345. flex-direction: column;
  346. align-items: center;
  347. // padding: 32rpx 32rpx;
  348. background-color: #ffffff;
  349. border-radius: 0 0 20rpx 20rpx;
  350. text-align: center;
  351. .delivery {
  352. font-size: 40rpx;
  353. color: #333333;
  354. display: flex;
  355. align-items: center;
  356. flex-direction: column;
  357. image {
  358. margin-top: 48rpx;
  359. width: 172rpx;
  360. height: 160rpx;
  361. }
  362. }
  363. .nocancel {
  364. font-size: 32rpx;
  365. color: #333333;
  366. margin-top: 14rpx;
  367. }
  368. .comfirm-box {
  369. margin-top: 52rpx;
  370. display: flex;
  371. // margin-bottom: 32rpx;
  372. // justify-content: space-around;
  373. .cancel {
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. width: 197rpx;
  378. height: 74rpx;
  379. border: 1px solid #dcc786;
  380. border-radius: 38rpx;
  381. font-size: 32rpx;
  382. color: #605128;
  383. }
  384. .comfirm {
  385. margin-left: 32rpx;
  386. display: flex;
  387. align-items: center;
  388. justify-content: center;
  389. width: 197rpx;
  390. height: 74rpx;
  391. background: linear-gradient(-90deg, #d1ba77 0%, #f7e8ad 100%);
  392. border-radius: 38px;
  393. font-size: 32rpx;
  394. color: #605128;
  395. }
  396. }
  397. }
  398. }
  399. .gcb {
  400. display: block;
  401. margin: 20rpx auto 0;
  402. width: 700rpx;
  403. border-radius: 20rpx;
  404. }
  405. </style>