index.vue 14 KB

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