index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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.getContentRectInfo();
  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){
  158. this.$refs.authRef.reLogin();
  159. }
  160. }
  161. }else{
  162. uni.setStorageSync('lastTime',new Date().getTime())
  163. }
  164. },
  165. methods: {
  166. // 切换导航
  167. switchTabbar(index) {
  168. this._switchTabbarPage(index)
  169. if (index !== 1) {
  170. this.$refs?.commRef?.stopAllVideo()
  171. }
  172. },
  173. //获取openId,unionid
  174. getOpenId(code) {
  175. const that = this;
  176. request.post('/wxma/code2Session',{
  177. code: code,
  178. platType: "slb",
  179. mpType: "engineer",
  180. }).then(res=>{
  181. console.error(res);
  182. if(res.success){
  183. //登录成功
  184. uni.setStorageSync('userMap', JSON.stringify(res.resultMap));
  185. }
  186. })
  187. },
  188. loginByCode(frontId) {
  189. const that = this;
  190. uni.setStorageSync('loginStatus', 'false');
  191. wx.getUserInfo({
  192. success: function(res) {
  193. console.error(res);
  194. request.post("/slbMpAutoLogin", {
  195. code:frontId,
  196. appType:'ma',
  197. encryptedData:res.encryptedData,
  198. iv: res.iv
  199. }, {
  200. login: false,
  201. warn:false,
  202. loading:false
  203. }).then(res2=>{
  204. console.error(res2);
  205. if(res2.success){
  206. //登录成功
  207. uni.setStorageSync('loginStatus', 'true');
  208. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  209. uni.setStorageSync('userNo', res2.resultMap.accountName);
  210. }else{
  211. console.error(12345);
  212. uni.setStorageSync('loginStatus', 'false');
  213. //登录失败,
  214. uni.login({
  215. success(res) {
  216. console.error(res);
  217. that.getOpenId(res.code);
  218. },
  219. fail(res) {
  220. console.error(res);
  221. uni.hideLoading();
  222. }
  223. });
  224. }
  225. console.error(res2);
  226. });
  227. }
  228. })
  229. },
  230. // 瀑布流导航页面滚动到底部
  231. tabbarPageScrollLower(e) {
  232. if (this.currentIndex === 0) {
  233. this.$refs.home.loadMore();
  234. }
  235. if (this.currentIndex === 1) {
  236. this.$refs.comm.loadMore();
  237. }
  238. if (this.currentIndex === 2) {
  239. }
  240. },
  241. onPulling(e) {
  242. console.log("onpulling", e);
  243. if(e.detail.deltaY<0){
  244. return
  245. }
  246. this.triggered = true
  247. },
  248. onRefresh(){
  249. if (this._freshing) return;
  250. this._freshing = true;
  251. if (this.currentIndex === 0) {
  252. console.error('this');
  253. this.$refs.home.reFetchData();
  254. }
  255. if (this.currentIndex === 1) {
  256. console.error('this');
  257. this.$refs.comm.reFetchData();
  258. }
  259. setTimeout(() => {
  260. this.triggered = false;
  261. this._freshing = false;
  262. }, 2000)
  263. },
  264. onRestore() {
  265. this.triggered = false; // 需要重置
  266. console.error("onRestore");
  267. },
  268. addButton() {
  269. if (!uni.getStorageSync('userNo')) {
  270. uni.showToast({
  271. title: '请登录',
  272. icon:'none'
  273. })
  274. uni.navigateTo({
  275. url: '/pages/login/login'
  276. })
  277. return false;
  278. } else {
  279. uni.navigateTo({
  280. url: this.currentIndex === 0?'/circlePages/circle':'/circlePages/addShare'
  281. })
  282. }
  283. //未登录,去登录
  284. //已登录,去新增第一步
  285. },
  286. reFetchData() {
  287. if (this.currentIndex === 0) {
  288. console.error('this');
  289. this.$refs.home.reFetchData();
  290. }
  291. if (this.currentIndex === 1) {
  292. console.error('this');
  293. this.$refs.comm.reFetchData();
  294. }
  295. },
  296. // 切换导航页面
  297. _switchTabbarPage(index) {
  298. const selectPageFlag = this.tabberPageLoadFlag[index]
  299. if (selectPageFlag === undefined) {
  300. return
  301. }
  302. if (selectPageFlag === false) {
  303. this.tabberPageLoadFlag[index] = true
  304. }
  305. this.currentIndex = index
  306. if (this.currentIndex === 2&&this.$refs.discovery) {
  307. this.$refs.discovery.fetchData();
  308. }
  309. },
  310. // 获取canvas实例和ctx画笔
  311. getMyCanvasAndCtx(id) {
  312. //id canvas 2d的id
  313. return new Promise((resolve) => {
  314. const query = wx.createSelectorQuery();
  315. query
  316. .select(`#${id}`)
  317. .fields({
  318. node: true,
  319. size: true,
  320. })
  321. .exec((res) => {
  322. const canvas = res[0].node;
  323. const ctx = canvas.getContext("2d");
  324. const dpr = wx.getSystemInfoSync().pixelRatio;
  325. canvas.width = res[0].width * dpr;
  326. canvas.height = res[0].height * dpr;
  327. ctx.scale(dpr, dpr);
  328. const data = {
  329. canvas,
  330. ctx,
  331. };
  332. resolve(data);
  333. });
  334. });
  335. },
  336. sleep(time) {
  337. return new Promise((resolve) => setTimeout(resolve, time));
  338. },
  339. async initCanvas(){
  340. // 保存画布
  341. const { ctx, canvas } = await this.getMyCanvasAndCtx("myCanvas");
  342. ctx.save();
  343. ctx.font = "24px";
  344. // ctx.textAlign = "center";
  345. ctx.fillText(this.shareData.company||this.shareData.contactPerson, 0, 32);
  346. // ctx.textAlign = "center";
  347. ctx.fillText(this.shareData.content, 0, 72);
  348. // sleep 500毫秒,等待图片加载完成 不然有可能圆形头像没有加载出来
  349. await this.sleep(500);
  350. let url = null;
  351. // 需要自行封装 canvasToTempFilePath
  352. const res = await wx.canvasToTempFilePath({ canvas });
  353. url = res.tempFilePath;
  354. return url;
  355. },
  356. addLog(shareData){
  357. const that = this;
  358. let params= {
  359. bisNo:shareData.bisNo,
  360. bisType:this.currentIndex === 0?'1':'2',
  361. userNo:uni.getStorageSync('userNo')
  362. };
  363. request.post('/slbForward/add',{slbForward:JSON.stringify(params)},{
  364. headers: {
  365. 'Content-Type': 'application/json', // 默认值
  366. },
  367. }).then(res=>{
  368. })
  369. },
  370. onShareAppMessage: function(option) {
  371. if(option.from=="button"){
  372. if (this.currentIndex === 0) {
  373. this.$refs.home.hideSheet();
  374. }
  375. if (this.currentIndex === 1) {
  376. this.$refs.comm.hideSheet();
  377. }
  378. this.shareData=option.target.dataset.coupon;
  379. this.addLog(this.shareData);
  380. const promise = new Promise(async (resolve) => {
  381. const url = await this.initCanvas();
  382. resolve({
  383. // title: `速立保`,
  384. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  385. // imageUrl: url,
  386. });
  387. });
  388. // 默认参数
  389. return {
  390. // title: `速立保`,
  391. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  392. promise,
  393. };
  394. }else{
  395. return {
  396. // title: '速立保',
  397. path: '/pages/index/index',
  398. // imageUrl: 'https://test-oss.lx-device.com/userFeedback/1733213748200dRV.png'
  399. };
  400. }
  401. },
  402. onShareAppMessage0: function(option) {
  403. if(option.from=="button"){
  404. if (this.currentIndex === 0) {
  405. this.$refs.home.hideSheet();
  406. }
  407. if (this.currentIndex === 1) {
  408. this.$refs.comm.hideSheet();
  409. }
  410. }
  411. return {
  412. title: '速立保',
  413. path: '/pages/index/index',
  414. };
  415. },
  416. }
  417. }
  418. </script>
  419. <style lang="scss" scoped>
  420. </style>