index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view class="start-index">
  3. <view v-if="tabberPageLoadFlag[1]" :style="{display: currentIndex === 1 ? '' : '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 :style="{fontSize:(wxFontSize)+'px'}">我要什么</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[2]" :style="{display: currentIndex === 2 ? '' : '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 :style="{fontSize:(wxFontSize)+'px'}">我有什么</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[0]" :style="{display: currentIndex === 0 ? '' : '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. <Mine ref="mine"></Mine>
  51. </scroll-view>
  52. </view>
  53. <Auth ref="authRef"></Auth>
  54. <tn-tabbar v-model="currentIndex" :iconSize="wxFontSize+23" :fontSize="wxFontSize+6" :list="tabbarList" activeColor="#1d60b1" inactiveColor="#AAAAAA"
  55. activeIconColor="#1d60b1" :animation="true" :safeAreaInsetBottom="true" @change="switchTabbar"></tn-tabbar>
  56. <canvas type="2d" id="myCanvas" style="width: 450px; height: 450px;left:9000px;position:fixed;"></canvas>
  57. </view>
  58. </template>
  59. <script>
  60. import Auth from '../index/autoLogin.vue'
  61. import Home from '../home/home.vue'
  62. import Comm from '../comm/comm.vue'
  63. import Discovery from '../discovery/discovery.vue'
  64. import Mine from '../mine/mine.vue'
  65. import request from '../../utils/request'
  66. export default {
  67. components: {
  68. Auth,
  69. Home,
  70. Comm,
  71. Discovery,
  72. Mine
  73. },
  74. data() {
  75. return {
  76. triggered: false,
  77. _freshing: false,
  78. // 底部tabbar菜单数据
  79. tabbarList: [
  80. {
  81. title: '供需发布平台',
  82. activeIcon: 'add-fill',
  83. inactiveIcon: 'add-circle',
  84. // count: 12
  85. },
  86. {
  87. title: '我要什么',
  88. activeIcon: 'trust-fill',
  89. inactiveIcon: 'trust'
  90. },
  91. {
  92. title: '我有什么',
  93. activeIcon: 'team-fill',
  94. inactiveIcon: 'team'
  95. },
  96. {
  97. title: '我的',
  98. activeIcon: 'my-fill',
  99. inactiveIcon: 'my'
  100. }
  101. ],
  102. // tabbar当前被选中的序号
  103. currentIndex: 0,
  104. // 自定义底栏对应页面的加载情况
  105. tabberPageLoadFlag: [],
  106. shareData:{},
  107. wxFontSize:17
  108. }
  109. },
  110. onLoad(options) {
  111. const appBaseInfo = wx.getAppBaseInfo();
  112. this.wxFontSize = uni.getStorageSync('fontSize')||appBaseInfo.fontSizeSetting||17;
  113. const index = Number(options.index || 0)
  114. // 根据底部tabbar菜单列表设置对应页面的加载情况
  115. this.tabberPageLoadFlag = this.tabbarList.map((item, tabbar_index) => {
  116. return index === tabbar_index
  117. })
  118. this._freshing = false;
  119. this.switchTabbar(index);
  120. let that = this;
  121. uni.hideShareMenu();
  122. },
  123. onShow(options){
  124. if (this.currentIndex === 3&&this.$refs.mine) {
  125. this.$refs.mine.fetchData();
  126. }
  127. if (this.currentIndex === 1&&this.$refs.comm) {
  128. this.$refs.comm.fetchData();
  129. }
  130. if (this.currentIndex === 2&&this.$refs.discovery) {
  131. this.$refs.discovery.fetchData();
  132. }
  133. if(uni.getStorageSync('lastTime')){
  134. //5*60s过期
  135. if(new Date().getTime()-uni.getStorageSync('lastTime')>5*60*1000||!uni.getStorageSync('userNo')){
  136. uni.setStorageSync('lastTime',new Date().getTime());
  137. if(this.$refs.authRef&&!uni.getStorageSync('loginOut')){
  138. // this.$refs.authRef.reLogin();
  139. }
  140. }
  141. }else{
  142. uni.setStorageSync('lastTime',new Date().getTime())
  143. }
  144. if(uni.getStorageSync('version')!='2.0.6'){
  145. uni.showModal({
  146. title: '更新提示',
  147. content: '新版本已经准备好,是否重启应用?\r\n 更新内容:优化产品体验,修复已知问题',
  148. success: (res) => {
  149. if (res.confirm) {
  150. uni.setStorageSync('version','2.0.6');
  151. uni.reLaunch({
  152. url:'/pages/index/index'
  153. })
  154. }
  155. }
  156. })
  157. }
  158. if(uni.getStorageSync('nextPage')&&uni.getStorageSync('userNo')){
  159. let nextPage = uni.getStorageSync('nextPage')
  160. uni.removeStorageSync('nextPage');
  161. uni.navigateTo({
  162. url: nextPage
  163. })
  164. }else{
  165. uni.removeStorageSync('nextPage')
  166. }
  167. if (wx.canIUse('getUpdateManager')) {
  168. const updateManager = wx.getUpdateManager();
  169. updateManager && updateManager.onCheckForUpdate((res) => {
  170. if (res.hasUpdate) {
  171. updateManager.onUpdateReady(() => {
  172. uni.showModal({
  173. title: '更新提示',
  174. content: '新版本已经准备好,是否重启应用?',
  175. success: (res) => {
  176. if (res.confirm) {
  177. uni.clearStorageSync() // 更新完成后刷新storage的数据
  178. updateManager.applyUpdate()
  179. }
  180. }
  181. })
  182. })
  183. updateManager.onUpdateFailed(() => {
  184. // uni.showModal({
  185. // title: '已有新版本上线',
  186. // content: '小程序自动更新失败,请删除该小程序后重新搜索打开哟~~~',
  187. // showCancel: false
  188. // })
  189. uni.reLaunch({
  190. url:'/pages/index/index'
  191. })
  192. })
  193. } else {
  194. //没有更新
  195. }
  196. })
  197. }
  198. },
  199. methods: {
  200. // 切换导航
  201. switchTabbar(index) {
  202. this._switchTabbarPage(index)
  203. },
  204. // 瀑布流导航页面滚动到底部
  205. tabbarPageScrollLower(e) {
  206. if (this.currentIndex === 1) {
  207. this.$refs.home.loadMore();
  208. }
  209. if (this.currentIndex === 2) {
  210. this.$refs.comm.loadMore();
  211. }
  212. },
  213. onPulling(e) {
  214. console.log("onpulling", e);
  215. if(e.detail.deltaY<0){
  216. return
  217. }
  218. this.triggered = true
  219. },
  220. onRefresh(){
  221. if (this._freshing) return;
  222. this._freshing = true;
  223. if (this.currentIndex === 1) {
  224. this.$refs.home.reFetchData();
  225. }
  226. if (this.currentIndex === 2) {
  227. this.$refs.comm.reFetchData();
  228. }
  229. setTimeout(() => {
  230. this.triggered = false;
  231. this._freshing = false;
  232. }, 2000)
  233. },
  234. onRestore() {
  235. this.triggered = false; // 需要重置
  236. },
  237. addButton() {
  238. if (!uni.getStorageSync('userNo')) {
  239. uni.showToast({
  240. title: '请登录',
  241. icon:'none'
  242. })
  243. uni.setStorageSync('nextPage',this.currentIndex === 1?'/circlePages/circle':'/circlePages/addShare');
  244. uni.navigateTo({
  245. url: '/pages/login/login'
  246. })
  247. return false;
  248. } else {
  249. uni.navigateTo({
  250. url: this.currentIndex === 1?'/circlePages/circle':'/circlePages/addShare'
  251. })
  252. }
  253. //未登录,去登录
  254. //已登录,去新增第一步
  255. },
  256. reFetchData() {
  257. if (this.currentIndex === 1) {
  258. console.error('this');
  259. this.$refs.home.reFetchData();
  260. }
  261. if (this.currentIndex === 2) {
  262. console.error('this');
  263. this.$refs.comm.reFetchData();
  264. }
  265. },
  266. // 切换导航页面
  267. _switchTabbarPage(index) {
  268. const selectPageFlag = this.tabberPageLoadFlag[index]
  269. if (selectPageFlag === undefined) {
  270. return
  271. }
  272. if (selectPageFlag === false) {
  273. this.tabberPageLoadFlag[index] = true
  274. }
  275. this.currentIndex = index
  276. if (this.currentIndex === 0&&this.$refs.discovery) {
  277. this.$refs.discovery.fetchData();
  278. }
  279. if (this.currentIndex === 3&&this.$refs.mine) {
  280. this.$refs.mine.fetchData();
  281. }
  282. },
  283. // 获取canvas实例和ctx画笔
  284. getMyCanvasAndCtx(id) {
  285. //id canvas 2d的id
  286. return new Promise((resolve) => {
  287. const query = wx.createSelectorQuery();
  288. query
  289. .select(`#${id}`)
  290. .fields({
  291. node: true,
  292. size: true,
  293. })
  294. .exec((res) => {
  295. const canvas = res[0].node;
  296. const ctx = canvas.getContext("2d");
  297. const dpr = wx.getSystemInfoSync().pixelRatio;
  298. canvas.width = res[0].width * dpr;
  299. canvas.height = res[0].height * dpr;
  300. ctx.scale(dpr, dpr);
  301. const data = {
  302. canvas,
  303. ctx,
  304. };
  305. resolve(data);
  306. });
  307. });
  308. },
  309. sleep(time) {
  310. return new Promise((resolve) => setTimeout(resolve, time));
  311. },
  312. async initCanvas(){
  313. // 保存画布
  314. const { ctx, canvas } = await this.getMyCanvasAndCtx("myCanvas");
  315. ctx.save();
  316. ctx.font = "24px";
  317. // ctx.textAlign = "center";
  318. ctx.fillText(this.shareData.company||this.shareData.contactPerson, 0, 32);
  319. // ctx.textAlign = "center";
  320. ctx.fillText(this.shareData.content, 0, 72);
  321. // sleep 500毫秒,等待图片加载完成 不然有可能圆形头像没有加载出来
  322. await this.sleep(500);
  323. let url = null;
  324. // 需要自行封装 canvasToTempFilePath
  325. const res = await wx.canvasToTempFilePath({ canvas });
  326. url = res.tempFilePath;
  327. return url;
  328. },
  329. addLog(shareData){
  330. const that = this;
  331. let params= {
  332. bisNo:shareData.bisNo,
  333. bisType:this.currentIndex === 0?'1':'2',
  334. userNo:uni.getStorageSync('userNo')
  335. };
  336. request.post('/slbForward/add',{slbForward:JSON.stringify(params)},{
  337. headers: {
  338. 'Content-Type': 'application/json', // 默认值
  339. },
  340. }).then(res=>{
  341. })
  342. },
  343. onShareAppMessage: function(option) {
  344. if(option.from=="button"){
  345. if (this.currentIndex === 1) {
  346. this.$refs.home.hideSheet();
  347. }
  348. if (this.currentIndex === 2) {
  349. this.$refs.comm.hideSheet();
  350. }
  351. this.shareData=option.target.dataset.coupon;
  352. this.addLog(this.shareData);
  353. const promise = new Promise(async (resolve) => {
  354. const url = await this.initCanvas();
  355. resolve({
  356. // title: `速立保`,
  357. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  358. // imageUrl: url,
  359. });
  360. });
  361. // 默认参数
  362. return {
  363. // title: `速立保`,
  364. path: `/pages/index/detail/detail?id=`+this.shareData.bisNo+'&isNeed='+(this.shareData.isNeed?1:0),
  365. promise,
  366. };
  367. }else{
  368. return {
  369. // title: '速立保',
  370. path: '/pages/index/index',
  371. };
  372. }
  373. }
  374. }
  375. }
  376. </script>
  377. <style lang="scss" scoped>
  378. </style>