index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <view class="start-index">
  3. <view v-if="tabberPageLoadFlag[0]" :style="{display: currentIndex === 0 ? '' : 'none'}">
  4. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  5. <Home ref="home"></Home>
  6. </scroll-view>
  7. </view>
  8. <view v-if="tabberPageLoadFlag[1]" :style="{display: currentIndex === 1 ? '' : 'none'}">
  9. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  10. <Comm ref="comm"></Comm>
  11. </scroll-view>
  12. </view>
  13. <view v-if="tabberPageLoadFlag[2]" :style="{display: currentIndex === 2 ? '' : 'none'}">
  14. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  15. <Discovery ref="discovery"></Discovery>
  16. </scroll-view>
  17. </view>
  18. <!-- <view v-if="tabberPageLoadFlag[3]" :style="{display: currentIndex === 3 ? '' : 'none'}">
  19. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  20. <Message ref="message"></Message>
  21. </scroll-view>
  22. </view> -->
  23. <view v-if="tabberPageLoadFlag[3]" :style="{display: currentIndex === 3 ? '' : 'none'}">
  24. <scroll-view class="custom-tabbar-page" scroll-y enable-back-to-top @scrolltolower="tabbarPageScrollLower">
  25. <Mine ref="mine"></Mine>
  26. </scroll-view>
  27. </view>
  28. <tn-tabbar v-model="currentIndex" :list="tabbarList" activeColor="#1d60b1" inactiveColor="#AAAAAA"
  29. activeIconColor="#1d60b1" :animation="true" :safeAreaInsetBottom="true" @change="switchTabbar"></tn-tabbar>
  30. <canvas type="2d" id="myCanvas" style="width: 450px; height: 450px;left:9000px;position:fixed;"></canvas>
  31. </view>
  32. </template>
  33. <script>
  34. import Home from '../home/home.vue'
  35. import Comm from '../comm/comm.vue'
  36. import Discovery from '../discovery/discovery.vue'
  37. import Mine from '../mine/mine.vue'
  38. import request from '../../utils/request'
  39. export default {
  40. components: {
  41. Home,
  42. Comm,
  43. Discovery,
  44. Mine
  45. },
  46. data() {
  47. return {
  48. // 底部tabbar菜单数据
  49. tabbarList: [{
  50. title: '我要什么',
  51. activeIcon: 'trust-fill',
  52. inactiveIcon: 'trust'
  53. },
  54. {
  55. title: '我有什么',
  56. activeIcon: 'team-fill',
  57. inactiveIcon: 'team'
  58. },
  59. // {
  60. // title: '发现',
  61. // activeIcon: 'rocket',
  62. // inactiveIcon: 'cube',
  63. // activeIconColor: '#FFFFFF',
  64. // inactiveIconColor: '#FFFFFF',
  65. // iconSize: 50,
  66. // out: true
  67. // },
  68. {
  69. title: '供需发布平台',
  70. activeIcon: 'add-fill',
  71. inactiveIcon: 'add-circle',
  72. // count: 12
  73. },
  74. {
  75. title: '我的',
  76. activeIcon: 'my-fill',
  77. inactiveIcon: 'my'
  78. }
  79. ],
  80. // tabbar当前被选中的序号
  81. currentIndex: 0,
  82. // 自定义底栏对应页面的加载情况
  83. tabberPageLoadFlag: [],
  84. shareData:{}
  85. }
  86. },
  87. onLoad(options) {
  88. const index = Number(options.index || 0)
  89. // 根据底部tabbar菜单列表设置对应页面的加载情况
  90. this.tabberPageLoadFlag = this.tabbarList.map((item, tabbar_index) => {
  91. return index === tabbar_index
  92. })
  93. this.switchTabbar(index);
  94. let that = this;
  95. // uni.login({
  96. // success(res) {
  97. // console.error(res);
  98. // that.loginByCode(res.code);
  99. // },
  100. // fail(res) {
  101. // console.error(res);
  102. // uni.hideLoading();
  103. // }
  104. // });
  105. },
  106. onShow(){
  107. if (this.currentIndex === 3&&this.$refs.mine) {
  108. this.$refs.mine.getContentRectInfo();
  109. }
  110. if (this.currentIndex === 1&&this.$refs.comm) {
  111. this.$refs.comm.fetchData();
  112. }
  113. },
  114. methods: {
  115. // 切换导航
  116. switchTabbar(index) {
  117. this._switchTabbarPage(index)
  118. if (index !== 1) {
  119. this.$refs?.commRef?.stopAllVideo()
  120. }
  121. },
  122. //获取openId,unionid
  123. getOpenId(code) {
  124. const that = this;
  125. request.post('/wxma/code2Session',{
  126. code: code,
  127. platType: "slb",
  128. mpType: "engineer",
  129. }).then(res=>{
  130. console.error(res);
  131. if(res.success){
  132. //登录成功
  133. uni.setStorageSync('userMap', JSON.stringify(res.resultMap));
  134. }
  135. })
  136. // wx.request({
  137. // method: 'post',
  138. // url: 'http://slb-m.dev.ml1993.com/lx-api/wxma/code2Session', //仅为示例,并非真实的接口地址
  139. // data: {
  140. // code: code,
  141. // platType: "slb",
  142. // mpType: "engineer",
  143. // },
  144. // header: {
  145. // 'content-type': 'application/json' ,// 默认值
  146. // platType: "slb",
  147. // mpType: "engineer",
  148. // },
  149. // success(res) {
  150. // console.warn(res);
  151. // //unionid存到本地
  152. // wx.setStorage({
  153. // key: "frontlixiangsid",
  154. // data: res.data.resultMap.frontlixiangsid
  155. // }, {
  156. // key: "userId",
  157. // data: res.data.resultMap.unionid
  158. // })
  159. // }
  160. // })
  161. },
  162. loginByCode(frontId) {
  163. const that = this;
  164. uni.setStorageSync('loginStatus', 'false');
  165. wx.getUserInfo({
  166. success: function(res) {
  167. console.error(res);
  168. request.post("/slbMpAutoLogin", {
  169. code:frontId,
  170. appType:'ma',
  171. encryptedData:res.encryptedData,
  172. iv: res.iv
  173. }, {
  174. login: false,
  175. warn:false,
  176. loading:false
  177. }).then(res2=>{
  178. console.error(res2);
  179. if(res2.success){
  180. //登录成功
  181. uni.setStorageSync('loginStatus', 'true');
  182. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  183. uni.setStorageSync('userNo', res2.resultMap.accountName);
  184. }else{
  185. console.error(12345);
  186. uni.setStorageSync('loginStatus', 'false');
  187. //登录失败,
  188. uni.login({
  189. success(res) {
  190. console.error(res);
  191. that.getOpenId(res.code);
  192. },
  193. fail(res) {
  194. console.error(res);
  195. uni.hideLoading();
  196. }
  197. });
  198. }
  199. console.error(res2);
  200. });
  201. // uni.request({
  202. // method: 'post',
  203. // url: 'http://slb-m.dev.ml1993.com/lx-api/slbMpAutoLogin', //仅为示例,并非真实的接口地址
  204. // data: {
  205. // code:frontId,
  206. // appType:'ma',
  207. // encryptedData:res.encryptedData,
  208. // iv: res.iv
  209. // },
  210. // header: {
  211. // 'content-type': 'application/json', // 默认值
  212. // platType: "slb",
  213. // mpType: "engineer",
  214. // },
  215. // success(res2) {
  216. // console.error(res2);
  217. // //unionid存到本地
  218. // }
  219. // })
  220. }
  221. })
  222. },
  223. // 瀑布流导航页面滚动到底部
  224. tabbarPageScrollLower(e) {
  225. if (this.currentIndex === 0) {
  226. this.$refs.home.loadMore();
  227. }
  228. if (this.currentIndex === 1) {
  229. this.$refs.comm.loadMore();
  230. }
  231. if (this.currentIndex === 2) {
  232. this.$refs.discovery.getRandomData && this.$refs.discovery.getRandomData()
  233. }
  234. },
  235. // 切换导航页面
  236. _switchTabbarPage(index) {
  237. const selectPageFlag = this.tabberPageLoadFlag[index]
  238. if (selectPageFlag === undefined) {
  239. return
  240. }
  241. if (selectPageFlag === false) {
  242. this.tabberPageLoadFlag[index] = true
  243. }
  244. this.currentIndex = index
  245. },
  246. // 获取canvas实例和ctx画笔
  247. getMyCanvasAndCtx(id) {
  248. //id canvas 2d的id
  249. return new Promise((resolve) => {
  250. const query = wx.createSelectorQuery();
  251. query
  252. .select(`#${id}`)
  253. .fields({
  254. node: true,
  255. size: true,
  256. })
  257. .exec((res) => {
  258. const canvas = res[0].node;
  259. const ctx = canvas.getContext("2d");
  260. const dpr = wx.getSystemInfoSync().pixelRatio;
  261. canvas.width = res[0].width * dpr;
  262. canvas.height = res[0].height * dpr;
  263. ctx.scale(dpr, dpr);
  264. const data = {
  265. canvas,
  266. ctx,
  267. };
  268. resolve(data);
  269. });
  270. });
  271. },
  272. sleep(time) {
  273. return new Promise((resolve) => setTimeout(resolve, time));
  274. },
  275. async initCanvas(){
  276. // 保存画布
  277. const { ctx, canvas } = await this.getMyCanvasAndCtx("myCanvas");
  278. ctx.save();
  279. ctx.font = "24px";
  280. // ctx.textAlign = "center";
  281. ctx.fillText(this.shareData.company||this.shareData.contactPerson, 0, 32);
  282. // ctx.textAlign = "center";
  283. ctx.fillText(this.shareData.content, 0, 72);
  284. // sleep 500毫秒,等待图片加载完成 不然有可能圆形头像没有加载出来
  285. await this.sleep(500);
  286. let url = null;
  287. // 需要自行封装 canvasToTempFilePath
  288. const res = await wx.canvasToTempFilePath({ canvas });
  289. url = res.tempFilePath;
  290. return url;
  291. },
  292. onShareAppMessage: function(option) {
  293. if(option.from=="button"){
  294. if (this.currentIndex === 0) {
  295. this.$refs.home.hideSheet();
  296. }
  297. if (this.currentIndex === 1) {
  298. this.$refs.comm.hideSheet();
  299. }
  300. this.shareData=option.target.dataset.coupon;
  301. const promise = new Promise(async (resolve) => {
  302. const url = await this.initCanvas();
  303. resolve({
  304. // title: `速立保`,
  305. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  306. // imageUrl: url,
  307. });
  308. });
  309. // 默认参数
  310. return {
  311. // title: `速立保`,
  312. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  313. promise,
  314. };
  315. }else{
  316. return {
  317. // title: '速立保',
  318. path: '/pages/index/index',
  319. // imageUrl: 'https://test-oss.lx-device.com/userFeedback/1733213748200dRV.png'
  320. };
  321. }
  322. },
  323. onShareAppMessage0: function(option) {
  324. if(option.from=="button"){
  325. if (this.currentIndex === 0) {
  326. this.$refs.home.hideSheet();
  327. }
  328. if (this.currentIndex === 1) {
  329. this.$refs.comm.hideSheet();
  330. }
  331. }
  332. return {
  333. title: '速立保',
  334. path: '/pages/index/index',
  335. };
  336. },
  337. }
  338. }
  339. </script>
  340. <style lang="scss" scoped>
  341. </style>