index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <view class="start-index">
  3. <view v-if="tabberPageLoadFlag[0]" :style="{display: currentIndex === 0 ? '' : 'none'}">
  4. <tn-nav-bar customBack>
  5. <view slot="back" class='tn-custom-nav-bar__back' @click="reFetchData()">
  6. <text v-if="!loading" class="tn-icon-circle-arrow" style="font-size: 50rpx;"></text>
  7. <view style="margin-top:6px" v-if="loading"><tn-loading :size="46"></tn-loading></view>
  8. </view>
  9. <view slot="default" style="display: flex;">
  10. <view style="flex:1;margin-left:25px;">
  11. <text>我要什么</text>
  12. </view>
  13. <view>
  14. <text class="tn-icon-add-fill" style="font-size: 30px;margin-right: 4px;"
  15. @click="addButton()"></text>
  16. </view>
  17. </view>
  18. </tn-nav-bar>
  19. <scroll-view class="custom-tabbar-page" :style="{marginTop: vuex_custom_bar_height + 'px'}" lower-threshold="60" scroll-y :refresher-enabled="true" @scroll="handleScroll" :refresher-triggered="triggered" @refresherpulling="onPulling" @refresherrestore="onRestore" @refresherrefresh="onRefresh" enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  20. <Home ref="home"></Home>
  21. </scroll-view>
  22. </view>
  23. <view v-if="tabberPageLoadFlag[1]" :style="{display: currentIndex === 1 ? '' : 'none'}">
  24. <tn-nav-bar customBack>
  25. <view slot="back" class='tn-custom-nav-bar__back' @click="reFetchData()">
  26. <text v-if="!loading" class="tn-icon-circle-arrow" style="font-size: 50rpx;"></text>
  27. <view style="margin-top:6px" v-if="loading" ><tn-loading :size="46"></tn-loading></view>
  28. </view>
  29. <view slot="default" style="display: flex;">
  30. <view style="flex:1;margin-left:25px">
  31. <text>我有什么</text>
  32. </view>
  33. <view>
  34. <text class="tn-icon-add-fill" style="font-size: 30px;margin-right: 4px;"
  35. @click="addButton()"></text>
  36. </view>
  37. </view>
  38. </tn-nav-bar>
  39. <scroll-view class="custom-tabbar-page" :style="{marginTop: vuex_custom_bar_height + 'px'}" scroll-y :refresher-enabled="true" :refresher-triggered="triggered" lower-threshold="60" @refresherrestore="onRestore" @refresherrefresh="onRefresh" @refresherpulling="onPulling" enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  40. <Comm ref="comm"></Comm>
  41. </scroll-view>
  42. </view>
  43. <view v-if="tabberPageLoadFlag[2]" :style="{display: currentIndex === 2 ? '' : 'none'}">
  44. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  45. <Discovery ref="discovery"></Discovery>
  46. </scroll-view>
  47. </view>
  48. <!-- <view v-if="tabberPageLoadFlag[3]" :style="{display: currentIndex === 3 ? '' : 'none'}">
  49. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  50. <Message ref="message"></Message>
  51. </scroll-view>
  52. </view> -->
  53. <view v-if="tabberPageLoadFlag[3]" :style="{display: currentIndex === 3 ? '' : 'none'}">
  54. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  55. <Mine ref="mine"></Mine>
  56. </scroll-view>
  57. </view>
  58. <tn-tabbar v-model="currentIndex" :list="tabbarList" activeColor="#1d60b1" inactiveColor="#AAAAAA"
  59. activeIconColor="#1d60b1" :animation="true" :safeAreaInsetBottom="true" @change="switchTabbar"></tn-tabbar>
  60. <canvas type="2d" id="myCanvas" style="width: 450px; height: 450px;left:9000px;position:fixed;"></canvas>
  61. </view>
  62. </template>
  63. <script>
  64. import Home from '../home/home.vue'
  65. import Comm from '../comm/comm.vue'
  66. import Discovery from '../discovery/discovery.vue'
  67. import Mine from '../mine/mine.vue'
  68. import request from '../../utils/request'
  69. export default {
  70. components: {
  71. Home,
  72. Comm,
  73. Discovery,
  74. Mine
  75. },
  76. data() {
  77. return {
  78. isTop: true,
  79. triggered: false,
  80. _freshing: false,
  81. // 底部tabbar菜单数据
  82. tabbarList: [{
  83. title: '我要什么',
  84. activeIcon: 'trust-fill',
  85. inactiveIcon: 'trust'
  86. },
  87. {
  88. title: '我有什么',
  89. activeIcon: 'team-fill',
  90. inactiveIcon: 'team'
  91. },
  92. // {
  93. // title: '发现',
  94. // activeIcon: 'rocket',
  95. // inactiveIcon: 'cube',
  96. // activeIconColor: '#FFFFFF',
  97. // inactiveIconColor: '#FFFFFF',
  98. // iconSize: 50,
  99. // out: true
  100. // },
  101. {
  102. title: '供需发布平台',
  103. activeIcon: 'add-fill',
  104. inactiveIcon: 'add-circle',
  105. // count: 12
  106. },
  107. {
  108. title: '我的',
  109. activeIcon: 'my-fill',
  110. inactiveIcon: 'my'
  111. }
  112. ],
  113. // tabbar当前被选中的序号
  114. currentIndex: 0,
  115. // 自定义底栏对应页面的加载情况
  116. tabberPageLoadFlag: [],
  117. shareData:{}
  118. }
  119. },
  120. onLoad(options) {
  121. const index = Number(options.index || 0)
  122. // 根据底部tabbar菜单列表设置对应页面的加载情况
  123. this.tabberPageLoadFlag = this.tabbarList.map((item, tabbar_index) => {
  124. return index === tabbar_index
  125. })
  126. this._freshing = false;
  127. this.switchTabbar(index);
  128. let that = this;
  129. // uni.login({
  130. // success(res) {
  131. // console.error(res);
  132. // that.loginByCode(res.code);
  133. // },
  134. // fail(res) {
  135. // console.error(res);
  136. // uni.hideLoading();
  137. // }
  138. // });
  139. },
  140. onShow(){
  141. if (this.currentIndex === 3&&this.$refs.mine) {
  142. this.$refs.mine.getContentRectInfo();
  143. }
  144. if (this.currentIndex === 1&&this.$refs.comm) {
  145. this.$refs.comm.fetchData();
  146. }
  147. },
  148. methods: {
  149. // 切换导航
  150. switchTabbar(index) {
  151. this._switchTabbarPage(index)
  152. if (index !== 1) {
  153. this.$refs?.commRef?.stopAllVideo()
  154. }
  155. },
  156. handleScroll(e){
  157. console.error('eee');
  158. console.error(e);
  159. console.error(e.detail.scrollTop);
  160. if(e.detail.scrollTop<1){
  161. console.error('11111111111111111');
  162. this.isTop = true;
  163. }else{
  164. this.isTop = false;
  165. }
  166. console.error(this.isTop,'11111111111111111');
  167. },
  168. //获取openId,unionid
  169. getOpenId(code) {
  170. const that = this;
  171. request.post('/wxma/code2Session',{
  172. code: code,
  173. platType: "slb",
  174. mpType: "engineer",
  175. }).then(res=>{
  176. console.error(res);
  177. if(res.success){
  178. //登录成功
  179. uni.setStorageSync('userMap', JSON.stringify(res.resultMap));
  180. }
  181. })
  182. // wx.request({
  183. // method: 'post',
  184. // url: 'http://slb-m.dev.ml1993.com/lx-api/wxma/code2Session', //仅为示例,并非真实的接口地址
  185. // data: {
  186. // code: code,
  187. // platType: "slb",
  188. // mpType: "engineer",
  189. // },
  190. // header: {
  191. // 'content-type': 'application/json' ,// 默认值
  192. // platType: "slb",
  193. // mpType: "engineer",
  194. // },
  195. // success(res) {
  196. // console.warn(res);
  197. // //unionid存到本地
  198. // wx.setStorage({
  199. // key: "frontlixiangsid",
  200. // data: res.data.resultMap.frontlixiangsid
  201. // }, {
  202. // key: "userId",
  203. // data: res.data.resultMap.unionid
  204. // })
  205. // }
  206. // })
  207. },
  208. loginByCode(frontId) {
  209. const that = this;
  210. uni.setStorageSync('loginStatus', 'false');
  211. wx.getUserInfo({
  212. success: function(res) {
  213. console.error(res);
  214. request.post("/slbMpAutoLogin", {
  215. code:frontId,
  216. appType:'ma',
  217. encryptedData:res.encryptedData,
  218. iv: res.iv
  219. }, {
  220. login: false,
  221. warn:false,
  222. loading:false
  223. }).then(res2=>{
  224. console.error(res2);
  225. if(res2.success){
  226. //登录成功
  227. uni.setStorageSync('loginStatus', 'true');
  228. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  229. uni.setStorageSync('userNo', res2.resultMap.accountName);
  230. }else{
  231. console.error(12345);
  232. uni.setStorageSync('loginStatus', 'false');
  233. //登录失败,
  234. uni.login({
  235. success(res) {
  236. console.error(res);
  237. that.getOpenId(res.code);
  238. },
  239. fail(res) {
  240. console.error(res);
  241. uni.hideLoading();
  242. }
  243. });
  244. }
  245. console.error(res2);
  246. });
  247. // uni.request({
  248. // method: 'post',
  249. // url: 'http://slb-m.dev.ml1993.com/lx-api/slbMpAutoLogin', //仅为示例,并非真实的接口地址
  250. // data: {
  251. // code:frontId,
  252. // appType:'ma',
  253. // encryptedData:res.encryptedData,
  254. // iv: res.iv
  255. // },
  256. // header: {
  257. // 'content-type': 'application/json', // 默认值
  258. // platType: "slb",
  259. // mpType: "engineer",
  260. // },
  261. // success(res2) {
  262. // console.error(res2);
  263. // //unionid存到本地
  264. // }
  265. // })
  266. }
  267. })
  268. },
  269. // 瀑布流导航页面滚动到底部
  270. tabbarPageScrollLower(e) {
  271. if (this.currentIndex === 0) {
  272. this.$refs.home.loadMore();
  273. }
  274. if (this.currentIndex === 1) {
  275. this.$refs.comm.loadMore();
  276. }
  277. if (this.currentIndex === 2) {
  278. this.$refs.discovery.getRandomData && this.$refs.discovery.getRandomData()
  279. }
  280. },
  281. onPulling(e) {
  282. console.log("onpulling", e);
  283. if(e.detail.deltaY<0){
  284. return
  285. }
  286. this.triggered = true
  287. },
  288. onRefresh(){
  289. if (this._freshing) return;
  290. this._freshing = true;
  291. if (this.currentIndex === 0) {
  292. console.error('this');
  293. this.$refs.home.reFetchData();
  294. }
  295. if (this.currentIndex === 1) {
  296. console.error('this');
  297. this.$refs.comm.reFetchData();
  298. }
  299. setTimeout(() => {
  300. console.error(11112222);
  301. this.triggered = false;
  302. this._freshing = false;
  303. this.isTop = false;
  304. }, 2000)
  305. },
  306. onRestore() {
  307. this.triggered = false; // 需要重置
  308. console.error("onRestore");
  309. },
  310. addButton() {
  311. if (!uni.getStorageSync('userNo')) {
  312. uni.showToast({
  313. title: '请登录',
  314. icon:'none'
  315. })
  316. uni.navigateTo({
  317. url: '/pages/login/login'
  318. })
  319. return false;
  320. } else {
  321. uni.navigateTo({
  322. url: this.currentIndex === 0?'/circlePages/circle':'/circlePages/addShare'
  323. })
  324. }
  325. //未登录,去登录
  326. //已登录,去新增第一步
  327. },
  328. reFetchData() {
  329. if (this.currentIndex === 0) {
  330. console.error('this');
  331. this.$refs.home.reFetchData();
  332. }
  333. if (this.currentIndex === 1) {
  334. console.error('this');
  335. this.$refs.comm.reFetchData();
  336. }
  337. },
  338. // 切换导航页面
  339. _switchTabbarPage(index) {
  340. const selectPageFlag = this.tabberPageLoadFlag[index]
  341. if (selectPageFlag === undefined) {
  342. return
  343. }
  344. if (selectPageFlag === false) {
  345. this.tabberPageLoadFlag[index] = true
  346. }
  347. this.currentIndex = index
  348. },
  349. // 获取canvas实例和ctx画笔
  350. getMyCanvasAndCtx(id) {
  351. //id canvas 2d的id
  352. return new Promise((resolve) => {
  353. const query = wx.createSelectorQuery();
  354. query
  355. .select(`#${id}`)
  356. .fields({
  357. node: true,
  358. size: true,
  359. })
  360. .exec((res) => {
  361. const canvas = res[0].node;
  362. const ctx = canvas.getContext("2d");
  363. const dpr = wx.getSystemInfoSync().pixelRatio;
  364. canvas.width = res[0].width * dpr;
  365. canvas.height = res[0].height * dpr;
  366. ctx.scale(dpr, dpr);
  367. const data = {
  368. canvas,
  369. ctx,
  370. };
  371. resolve(data);
  372. });
  373. });
  374. },
  375. sleep(time) {
  376. return new Promise((resolve) => setTimeout(resolve, time));
  377. },
  378. async initCanvas(){
  379. // 保存画布
  380. const { ctx, canvas } = await this.getMyCanvasAndCtx("myCanvas");
  381. ctx.save();
  382. ctx.font = "24px";
  383. // ctx.textAlign = "center";
  384. ctx.fillText(this.shareData.company||this.shareData.contactPerson, 0, 32);
  385. // ctx.textAlign = "center";
  386. ctx.fillText(this.shareData.content, 0, 72);
  387. // sleep 500毫秒,等待图片加载完成 不然有可能圆形头像没有加载出来
  388. await this.sleep(500);
  389. let url = null;
  390. // 需要自行封装 canvasToTempFilePath
  391. const res = await wx.canvasToTempFilePath({ canvas });
  392. url = res.tempFilePath;
  393. return url;
  394. },
  395. onShareAppMessage: function(option) {
  396. if(option.from=="button"){
  397. if (this.currentIndex === 0) {
  398. this.$refs.home.hideSheet();
  399. }
  400. if (this.currentIndex === 1) {
  401. this.$refs.comm.hideSheet();
  402. }
  403. this.shareData=option.target.dataset.coupon;
  404. const promise = new Promise(async (resolve) => {
  405. const url = await this.initCanvas();
  406. resolve({
  407. // title: `速立保`,
  408. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  409. // imageUrl: url,
  410. });
  411. });
  412. // 默认参数
  413. return {
  414. // title: `速立保`,
  415. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  416. promise,
  417. };
  418. }else{
  419. return {
  420. // title: '速立保',
  421. path: '/pages/index/index',
  422. // imageUrl: 'https://test-oss.lx-device.com/userFeedback/1733213748200dRV.png'
  423. };
  424. }
  425. },
  426. onShareAppMessage0: function(option) {
  427. if(option.from=="button"){
  428. if (this.currentIndex === 0) {
  429. this.$refs.home.hideSheet();
  430. }
  431. if (this.currentIndex === 1) {
  432. this.$refs.comm.hideSheet();
  433. }
  434. }
  435. return {
  436. title: '速立保',
  437. path: '/pages/index/index',
  438. };
  439. },
  440. }
  441. }
  442. </script>
  443. <style lang="scss" scoped>
  444. </style>