| | |
| | | }) |
| | | } |
| | | // 获取会员信息 |
| | | export const getMemberInfo = () => { |
| | | export const getMemberInfo = (data) => { |
| | | return request({ |
| | | url: '/web/customer/getMemberInfo', |
| | | data |
| | | }) |
| | | } |
| | | // 首页 志说装修 |
| | |
| | | import { |
| | | wxLoginCustomer |
| | | wxLoginCustomer, |
| | | getMemberInfo |
| | | } from './api/index' |
| | | import CustomHook from 'spa-custom-hooks'; |
| | | let globalData = { |
| | |
| | | this.globalData.bottomLift = WindowInfo.screenHeight - WindowInfo.safeArea.bottom |
| | | } |
| | | // 授权登录 |
| | | wx.login({ |
| | | timeout: 5000, |
| | | success: (res) => { |
| | | var userId = null |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | userId = temp[2] |
| | | } |
| | | if (res.code) { |
| | | //发起网络请求 |
| | | wxLoginCustomer({ |
| | | code: res.code, |
| | | userId |
| | | }).then(res => { |
| | | wx.setStorageSync('token', res.data.token) |
| | | this.globalData.token = res.data.token |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | wx.navigateTo({ |
| | | url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`, |
| | | }) |
| | | } |
| | | console.log('拿到token了', res.data.token); |
| | | if (res && res.data.member) { |
| | | wx.setStorageSync('member', res.data.member) |
| | | wx.setStorageSync('openid', res.data.member.openid) |
| | | wx.setStorageSync('sessionKey', res.data.sessionKey) |
| | | } else { |
| | | console.log('登录失败!') |
| | | var userId = null |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | userId = temp[2] |
| | | } |
| | | const token = wx.getStorageSync('token') || '' |
| | | if (token) { |
| | | getMemberInfo({ |
| | | isAuth: true |
| | | }).then(res => { |
| | | if (res.code !== 200) { |
| | | setTimeout(() => { |
| | | wx.showLoading({ |
| | | title: '正在重新登录...', |
| | | mask: true |
| | | }) |
| | | }, 200) |
| | | setTimeout(() => { |
| | | wx.hideLoading() |
| | | }, 1000) |
| | | wx.login({ |
| | | timeout: 5000, |
| | | success: (res) => { |
| | | var userId = null |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | userId = temp[2] |
| | | } |
| | | if (res.code) { |
| | | //发起网络请求 |
| | | wxLoginCustomer({ |
| | | code: res.code, |
| | | userId |
| | | }).then(res => { |
| | | wx.setStorageSync('token', res.data.token) |
| | | this.globalData.token = res.data.token |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | wx.navigateTo({ |
| | | url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`, |
| | | }) |
| | | } |
| | | console.log('拿到token了', res.data.token); |
| | | if (res && res.data.member) { |
| | | wx.setStorageSync('member', res.data.member) |
| | | wx.setStorageSync('openid', res.data.member.openid) |
| | | wx.setStorageSync('sessionKey', res.data.sessionKey) |
| | | } else { |
| | | console.log('登录失败!') |
| | | } |
| | | }) |
| | | } else { |
| | | console.log('登录失败!' + res) |
| | | } |
| | | }, |
| | | fail(err) { |
| | | console.log(err) |
| | | } |
| | | }) |
| | | } else { |
| | | console.log('登录失败!' + res) |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | wx.navigateTo({ |
| | | url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`, |
| | | }) |
| | | } |
| | | } |
| | | }, |
| | | fail(err) { |
| | | console.log(err) |
| | | } |
| | | }) |
| | | |
| | | }) |
| | | } else { |
| | | // 授权登录 |
| | | wx.login({ |
| | | timeout: 5000, |
| | | success: (res) => { |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | userId = temp[2] |
| | | } |
| | | if (res.code) { |
| | | //发起网络请求 |
| | | wxLoginCustomer({ |
| | | code: res.code, |
| | | userId |
| | | }).then(res => { |
| | | wx.setStorageSync('token', res.data.token) |
| | | this.globalData.token = res.data.token |
| | | if (op.query.scene) { |
| | | let temp = op.query.scene.split('_') |
| | | wx.navigateTo({ |
| | | url: `${pathMap[temp[1]]}?id=${temp[0]}&userId=${temp[2]}`, |
| | | }) |
| | | } |
| | | console.log('拿到token了', res.data.token); |
| | | if (res && res.data.member) { |
| | | wx.setStorageSync('member', res.data.member) |
| | | wx.setStorageSync('openid', res.data.member.openid) |
| | | wx.setStorageSync('sessionKey', res.data.sessionKey) |
| | | } else { |
| | | console.log('登录失败!') |
| | | } |
| | | }) |
| | | } else { |
| | | console.log('登录失败!' + res) |
| | | } |
| | | }, |
| | | fail(err) { |
| | | console.log(err) |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | onShow(options) { |
| | | console.log('options', options); |
| | | } |
| | | }) |
| | | CustomHook.install({ |
| | | 'Login':{ |
| | | name:'Login', |
| | | watchKey: 'token', |
| | | onUpdate(val){ |
| | | //有token则触发此钩子 |
| | | return !!val; |
| | | } |
| | | } |
| | | }, globalData || 'globalData') |
| | | 'Login': { |
| | | name: 'Login', |
| | | watchKey: 'token', |
| | | onUpdate(val) { |
| | | //有token则触发此钩子 |
| | | return !!val; |
| | | } |
| | | } |
| | | }, globalData || 'globalData') |
| | |
| | | }, |
| | | itemClick(e) { |
| | | const item = e.currentTarget.dataset.item |
| | | const { dataList } = this.data |
| | | dataList.forEach(ite => { |
| | | if(item.id === ite.id){ |
| | | ite.viewCount += 1 |
| | | } |
| | | }) |
| | | this.setData({ dataList }) |
| | | actionDo({actionType: 'view',id: item.id}) |
| | | if(item.contentType == 'link'){ |
| | | wx.navigateTo({ |
| | |
| | | }, |
| | | itemClick(e) { |
| | | const item = e.currentTarget.dataset.item |
| | | const { dataList } = this.data |
| | | dataList.forEach(ite => { |
| | | if(item.id === ite.id){ |
| | | ite.viewCount += 1 |
| | | } |
| | | }) |
| | | this.setData({ dataList }) |
| | | if(item.contentType){ |
| | | actionDo({actionType: 'view',id: item.id}) |
| | | } |
| | |
| | | }) |
| | | }, |
| | | onLoad(options) { |
| | | const member = wx.getStorageSync('member') |
| | | this.initDictData() |
| | | this.initData() |
| | | }, |
| | | changePath(e) { |
| | | let index = e.currentTarget.dataset.type |
| | |
| | | }) |
| | | }, |
| | | itemClick(e) { |
| | | |
| | | const { videourl ,id} = e.currentTarget.dataset |
| | | const { dataList } = this.data |
| | | dataList.forEach(ite => { |
| | | if(id === ite.id){ |
| | | ite.viewCount += 1 |
| | | } |
| | | }) |
| | | this.setData({ dataList }) |
| | | actionDo({ |
| | | actionType: 'view', |
| | | id: id |
| | | }) |
| | | var dataList = this.data.dataList; |
| | | dataList.forEach(item =>{ |
| | | if(item.id == id){ |
| | | item.viewCount = (item.viewCount||0) +1 |
| | | } |
| | | }) |
| | | this.setData({dataList:dataList}) |
| | | let videoPlay = this.selectComponent('.videoPlay'); |
| | | if(videoPlay){ |
| | | videoPlay.startPlayVideo(videourl,this ); |
| | |
| | | import { |
| | | collectLikePage |
| | | } from '../../api/index' |
| | | import { |
| | | eventBus |
| | | } from '../../utils/eventBus' |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | }, |
| | | onLoad(options) { |
| | | this.getList() |
| | | }, |
| | | onShow() { |
| | | const dataList = this.data.dataList |
| | | eventBus.once('caseDeBack', (info) => { |
| | | const temp = dataList.filter(item => { |
| | | if (item.id === info.id) { |
| | | item.isCollection = info.isCollection |
| | | item.viewCount++ |
| | | } |
| | | if(item.isCollection) return item |
| | | }) |
| | | this.setData({ dataList: temp}) |
| | | }) |
| | | eventBus.once('productDeBack', (info) => { |
| | | const temp = dataList.filter(item => { |
| | | if (item.id === info.id) { |
| | | item.isCollection = info.isCollection |
| | | item.viewCount++ |
| | | } |
| | | if(item.isCollection) return item |
| | | }) |
| | | this.setData({ dataList: temp}) |
| | | }) |
| | | eventBus.once('realpicDeBack', (info) => { |
| | | const temp = dataList.filter(item => { |
| | | if (item.id === info.id) { |
| | | item.isCollection = info.isCollection |
| | | item.viewCount++ |
| | | } |
| | | if(item.isCollection) return item |
| | | }) |
| | | this.setData({ dataList: temp}) |
| | | }) |
| | | }, |
| | | onPullDownRefresh: function () { |
| | | console.log('下拉刷新'); |
| | |
| | | onReady() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面显示 |
| | | */ |
| | | onShow() { |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面隐藏 |
| | | */ |
| | | onHide() { |
| | | |
| | | }, |
| | |
| | | <view class="info"> |
| | | <image wx:if="{{ false }}" class="icon" src="../../static/icon/detail_nav_collect.png" mode="widthFix"></image> |
| | | <image wx:else="" class="icon" src="../../static/icon/detail_nav_collected.png" mode="widthFix"></image> |
| | | <text class="num {{true ? 'primary' : ''}}">34</text> |
| | | <text class="num {{true ? 'primary' : ''}}">{{ item.collectCount }}</text> |
| | | <image class="icon" src="../../static/icon/zixun_ic_liulan.png" mode="widthFix"></image> |
| | | <text>1000</text> |
| | | <text>{{ item.viewCount }}</text> |
| | | </view> |
| | | </view> |
| | | <view wx:if="{{ dataList.length == 0 }}" class="empty_wrap"> |
| | |
| | | import { baseUrl } from "./config" |
| | | import { |
| | | baseUrl |
| | | } from "./config" |
| | | let number = 0 |
| | | export function request(options){ |
| | | export function request(options) { |
| | | let loading = options.loading || '1' // 默认值1显示,否则不显示 |
| | | if(loading == '1'){ |
| | | wx.showLoading({mask: true}) |
| | | number ++ |
| | | if (loading == '1') { |
| | | wx.showLoading({ |
| | | mask: true |
| | | }) |
| | | number++ |
| | | } |
| | | return new Promise(resolve => { |
| | | wx.request({ |
| | |
| | | if (res.data.code === 200) { |
| | | resolve(res.data || true) |
| | | } else { |
| | | if(res.data.code == 5111 || res.data.code == 5112){ |
| | | wx.switchTab({ |
| | | url: '/pages/index/index', |
| | | if (options.data && options.data.isAuth && (res.data.code == 5111 || res.data.code == 5112 || res.data.code == 5110)) { |
| | | // wx.switchTab({ |
| | | // url: '/pages/index/index', |
| | | // }) |
| | | resolve(res.data) |
| | | res.data.message && wx.showToast({ |
| | | title: res.data.message || '发生错误', |
| | | icon: 'none' |
| | | }) |
| | | return |
| | | } |
| | | if(res.data.code == 5111 || res.data.code == 5112 || res.data.code == 5110){ |
| | | return |
| | | } |
| | | res.data.message && wx.showToast({ |
| | | title: res.data.message || '发生错误', |
| | |
| | | }) |
| | | }, |
| | | complete() { |
| | | if(loading == '1'){ |
| | | number -- |
| | | if(number == 0){ |
| | | if (loading == '1') { |
| | | number-- |
| | | if (number == 0) { |
| | | wx.hideLoading() |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | } ) |
| | | } |
| | | |
| | | }) |
| | | } |
| | |
| | | itemClick(e) { |
| | | const item = e.currentTarget.dataset.item |
| | | actionDo({actionType: 'view',id: item.id}) |
| | | const { dataList } = this.data |
| | | dataList.forEach(ite => { |
| | | if(item.id === ite.id){ |
| | | ite.viewCount += 1 |
| | | } |
| | | }) |
| | | this.setData({ dataList }) |
| | | if(item.contentType == 'link'){ |
| | | wx.navigateTo({ |
| | | url: '/pages/webView/index', |
| | |
| | | actionType: flag ? 'collect' : 'collect_cancel' |
| | | }).then(res => { |
| | | info.isCollection = flag |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏'}) |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏',icon: 'none'}) |
| | | this.setData({ |
| | | info |
| | | }) |
| | |
| | | this.setData({info}) |
| | | wx.showToast({ |
| | | title: actionType == 'collect' ? '收藏成功' : '取消收藏', |
| | | icon: 'none' |
| | | }) |
| | | }) |
| | | }, |
| | |
| | | actionType: flag ? 'collect' : 'collect_cancel' |
| | | }).then(res => { |
| | | info.isCollection = flag |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏'}) |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏', icon: 'none'}) |
| | | this.setData({ |
| | | info |
| | | }) |
| | |
| | | info.isCollection = !info.isCollection |
| | | wx.showToast({ |
| | | title: actionType == 'collect' ? '收藏成功' : '取消收藏', |
| | | icon: 'none' |
| | | }) |
| | | this.setData({info}) |
| | | }) |
| | |
| | | actionType: flag ? 'collect' : 'collect_cancel' |
| | | }).then(res => { |
| | | info.isCollection = flag |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏'}) |
| | | wx.showToast({title: flag ? '收藏成功' : '取消收藏', icon: 'none'}) |
| | | this.setData({ |
| | | info |
| | | }) |
| | |
| | | }, |
| | | itemClick(e) { |
| | | const item = e.currentTarget.dataset.item |
| | | console.log('item', item); |
| | | const { dataList } = this.data |
| | | dataList.forEach(ite => { |
| | | if(item.id === ite.id){ |
| | | ite.viewCount += 1 |
| | | } |
| | | }) |
| | | this.setData({ dataList }) |
| | | if(item.contentType == 'video'){ |
| | | wx.previewMedia({ |
| | | sources: [{ url: item.content, type: 'video' }] |