index.vue 12 KB

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