index.vue 14 KB

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