index.vue 14 KB

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