index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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.hideShareMenu();
  130. // uni.login({
  131. // success(res) {
  132. // console.error(res);
  133. // that.loginByCode(res.code);
  134. // },
  135. // fail(res) {
  136. // console.error(res);
  137. // uni.hideLoading();
  138. // }
  139. // });
  140. },
  141. onShow(){
  142. if (this.currentIndex === 3&&this.$refs.mine) {
  143. this.$refs.mine.getContentRectInfo();
  144. }
  145. if (this.currentIndex === 1&&this.$refs.comm) {
  146. this.$refs.comm.fetchData();
  147. }
  148. },
  149. methods: {
  150. // 切换导航
  151. switchTabbar(index) {
  152. this._switchTabbarPage(index)
  153. if (index !== 1) {
  154. this.$refs?.commRef?.stopAllVideo()
  155. }
  156. },
  157. handleScroll(e){
  158. console.error('eee');
  159. console.error(e);
  160. console.error(e.detail.scrollTop);
  161. if(e.detail.scrollTop<1){
  162. console.error('11111111111111111');
  163. this.isTop = true;
  164. }else{
  165. this.isTop = false;
  166. }
  167. console.error(this.isTop,'11111111111111111');
  168. },
  169. //获取openId,unionid
  170. getOpenId(code) {
  171. const that = this;
  172. request.post('/wxma/code2Session',{
  173. code: code,
  174. platType: "slb",
  175. mpType: "engineer",
  176. }).then(res=>{
  177. console.error(res);
  178. if(res.success){
  179. //登录成功
  180. uni.setStorageSync('userMap', JSON.stringify(res.resultMap));
  181. }
  182. })
  183. // wx.request({
  184. // method: 'post',
  185. // url: 'http://slb-m.dev.ml1993.com/lx-api/wxma/code2Session', //仅为示例,并非真实的接口地址
  186. // data: {
  187. // code: code,
  188. // platType: "slb",
  189. // mpType: "engineer",
  190. // },
  191. // header: {
  192. // 'content-type': 'application/json' ,// 默认值
  193. // platType: "slb",
  194. // mpType: "engineer",
  195. // },
  196. // success(res) {
  197. // console.warn(res);
  198. // //unionid存到本地
  199. // wx.setStorage({
  200. // key: "frontlixiangsid",
  201. // data: res.data.resultMap.frontlixiangsid
  202. // }, {
  203. // key: "userId",
  204. // data: res.data.resultMap.unionid
  205. // })
  206. // }
  207. // })
  208. },
  209. loginByCode(frontId) {
  210. const that = this;
  211. uni.setStorageSync('loginStatus', 'false');
  212. wx.getUserInfo({
  213. success: function(res) {
  214. console.error(res);
  215. request.post("/slbMpAutoLogin", {
  216. code:frontId,
  217. appType:'ma',
  218. encryptedData:res.encryptedData,
  219. iv: res.iv
  220. }, {
  221. login: false,
  222. warn:false,
  223. loading:false
  224. }).then(res2=>{
  225. console.error(res2);
  226. if(res2.success){
  227. //登录成功
  228. uni.setStorageSync('loginStatus', 'true');
  229. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  230. uni.setStorageSync('userNo', res2.resultMap.accountName);
  231. }else{
  232. console.error(12345);
  233. uni.setStorageSync('loginStatus', 'false');
  234. //登录失败,
  235. uni.login({
  236. success(res) {
  237. console.error(res);
  238. that.getOpenId(res.code);
  239. },
  240. fail(res) {
  241. console.error(res);
  242. uni.hideLoading();
  243. }
  244. });
  245. }
  246. console.error(res2);
  247. });
  248. // uni.request({
  249. // method: 'post',
  250. // url: 'http://slb-m.dev.ml1993.com/lx-api/slbMpAutoLogin', //仅为示例,并非真实的接口地址
  251. // data: {
  252. // code:frontId,
  253. // appType:'ma',
  254. // encryptedData:res.encryptedData,
  255. // iv: res.iv
  256. // },
  257. // header: {
  258. // 'content-type': 'application/json', // 默认值
  259. // platType: "slb",
  260. // mpType: "engineer",
  261. // },
  262. // success(res2) {
  263. // console.error(res2);
  264. // //unionid存到本地
  265. // }
  266. // })
  267. }
  268. })
  269. },
  270. // 瀑布流导航页面滚动到底部
  271. tabbarPageScrollLower(e) {
  272. if (this.currentIndex === 0) {
  273. this.$refs.home.loadMore();
  274. }
  275. if (this.currentIndex === 1) {
  276. this.$refs.comm.loadMore();
  277. }
  278. if (this.currentIndex === 2) {
  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. addLog(shareData){
  396. const that = this;
  397. let params= {
  398. bisNo:shareData.bisNo,
  399. bisType:this.currentIndex === 0?'1':'2',
  400. userNo:uni.getStorageSync('userNo')
  401. };
  402. request.post('/slbForward/add',{slbForward:JSON.stringify(params)},{
  403. headers: {
  404. 'Content-Type': 'application/json', // 默认值
  405. },
  406. }).then(res=>{
  407. })
  408. },
  409. onShareAppMessage: function(option) {
  410. if(option.from=="button"){
  411. if (this.currentIndex === 0) {
  412. this.$refs.home.hideSheet();
  413. }
  414. if (this.currentIndex === 1) {
  415. this.$refs.comm.hideSheet();
  416. }
  417. this.shareData=option.target.dataset.coupon;
  418. this.addLog(this.shareData);
  419. const promise = new Promise(async (resolve) => {
  420. const url = await this.initCanvas();
  421. resolve({
  422. // title: `速立保`,
  423. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  424. // imageUrl: url,
  425. });
  426. });
  427. // 默认参数
  428. return {
  429. // title: `速立保`,
  430. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  431. promise,
  432. };
  433. }else{
  434. return {
  435. // title: '速立保',
  436. path: '/pages/index/index',
  437. // imageUrl: 'https://test-oss.lx-device.com/userFeedback/1733213748200dRV.png'
  438. };
  439. }
  440. },
  441. onShareAppMessage0: function(option) {
  442. if(option.from=="button"){
  443. if (this.currentIndex === 0) {
  444. this.$refs.home.hideSheet();
  445. }
  446. if (this.currentIndex === 1) {
  447. this.$refs.comm.hideSheet();
  448. }
  449. }
  450. return {
  451. title: '速立保',
  452. path: '/pages/index/index',
  453. };
  454. },
  455. }
  456. }
  457. </script>
  458. <style lang="scss" scoped>
  459. </style>