index.vue 12 KB

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