263 lines
6.7 KiB
JavaScript
263 lines
6.7 KiB
JavaScript
|
// pages/mine/index/index.js
|
||
|
const app = getApp()
|
||
|
var audioContext = wx.createInnerAudioContext()
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
nickName: '昵称',
|
||
|
name: '用户名称',
|
||
|
userIcon: '../../../images/ic_user_default.png',
|
||
|
menuList: [],
|
||
|
imgUrl: app.urls.baseImgUrl,
|
||
|
audioFile: {
|
||
|
path: 'http://www.170mv.com/kw/antiserver.kuwo.cn/anti.s?rid=MUSIC_96145895&response=res&format=mp3|aac&type=convert_url&br=128kmp3&agent=iPhone&callback=getlink&jpcallback=getlink.mp3',
|
||
|
isPlay: false,
|
||
|
duration: 0,
|
||
|
curDuration: 0
|
||
|
},
|
||
|
speedStep: 5, //快进快退秒数
|
||
|
curTimeStr: '00:00',
|
||
|
totalTimeStr: '00:60', //总时长
|
||
|
waitFlag: false,
|
||
|
url: 'https://ossweb-img.qq.com/images/lol/img/champion/Morgana.png'
|
||
|
},
|
||
|
/**
|
||
|
* 生命周期函数--监听页面加载
|
||
|
*/
|
||
|
onLoad(options) {
|
||
|
var _self = this
|
||
|
_self.setData({
|
||
|
nickName: app.globalData.userInfo.name
|
||
|
})
|
||
|
_self.checkPermission()
|
||
|
|
||
|
},
|
||
|
getItemList() {
|
||
|
wx.showLoading({
|
||
|
title: '加载中...',
|
||
|
})
|
||
|
var _self = this
|
||
|
app.http.get(app.urls.getMenuList, {
|
||
|
header: {
|
||
|
token: app.globalData.token
|
||
|
}
|
||
|
})
|
||
|
.then(res => {
|
||
|
wx.stopPullDownRefresh({})
|
||
|
wx.hideLoading({})
|
||
|
data.sort((a, b) => a.configSort - b.configSort)
|
||
|
_self.setData({
|
||
|
menuList: data
|
||
|
})
|
||
|
})
|
||
|
.catch(err => {
|
||
|
console.log(err)
|
||
|
wx.stopPullDownRefresh({})
|
||
|
wx.hideLoading({})
|
||
|
})
|
||
|
},
|
||
|
checkPermission() {
|
||
|
var _self = this
|
||
|
try {
|
||
|
var names = wx.getStorageSync('name')
|
||
|
var icon = wx.getStorageSync('userIcon')
|
||
|
if (names) {
|
||
|
this.setData({
|
||
|
name: names,
|
||
|
userIcon: icon
|
||
|
})
|
||
|
} else {
|
||
|
wx.showModal({
|
||
|
title: '提示',
|
||
|
content: '小程序需要您微信头像以及昵称用于展示,请授权.',
|
||
|
showCancel: false,
|
||
|
success(res) {
|
||
|
console.log(res)
|
||
|
if (res.confirm) {
|
||
|
_self.getUserProfile(3)
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
} catch (error) {
|
||
|
wx.showToast({
|
||
|
title: '获取信息失败',
|
||
|
icon: 'error'
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
getUserProfile(e) {
|
||
|
let _self = this
|
||
|
wx.getUserProfile({
|
||
|
desc: '获取微信头像以及昵称用于展示',
|
||
|
success: (res) => {
|
||
|
wx.setStorage({
|
||
|
data: res.userInfo.nickName,
|
||
|
key: 'name',
|
||
|
})
|
||
|
wx.setStorage({
|
||
|
data: res.userInfo.avatarUrl,
|
||
|
key: 'userIcon',
|
||
|
})
|
||
|
_self.setData({
|
||
|
name: res.userInfo.nickName,
|
||
|
userIcon: res.userInfo.avatarUrl
|
||
|
})
|
||
|
},
|
||
|
fail(err) {
|
||
|
//判断是否绑定手机号
|
||
|
wx.showToast({
|
||
|
title: '获取个人信息失败',
|
||
|
icon: 'error',
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
addShop() {
|
||
|
wx.navigateTo({
|
||
|
url: '../shop/addshop',
|
||
|
})
|
||
|
},
|
||
|
onShow() {
|
||
|
this.setData({
|
||
|
nickName: app.globalData.userInfo.name
|
||
|
})
|
||
|
this.getItemList()
|
||
|
},
|
||
|
//item 状态 1 待付款 2待发货 3待收货 4售后/退款
|
||
|
showOrder(e) {
|
||
|
var item = e.currentTarget.dataset.item
|
||
|
console.log(item)
|
||
|
var path = '/pages/mine/order/orderlist?status=' + item
|
||
|
wx.navigateTo({
|
||
|
url: path,
|
||
|
})
|
||
|
},
|
||
|
choosePage(e) {
|
||
|
var path = e.currentTarget.dataset.path
|
||
|
var type = e.currentTarget.dataset.type
|
||
|
switch (type) {
|
||
|
case 'mini': //跳转小程序内部
|
||
|
case 'webview': //链接
|
||
|
wx.navigateTo({
|
||
|
url: path,
|
||
|
})
|
||
|
break
|
||
|
case 'othermini': //其他小程序
|
||
|
wx.navigateToMiniProgram({
|
||
|
appId: '',
|
||
|
success(res) {
|
||
|
// 打开成功
|
||
|
}
|
||
|
})
|
||
|
break
|
||
|
}
|
||
|
},
|
||
|
onPullDownRefresh() {
|
||
|
this.getItemList()
|
||
|
},
|
||
|
play() {
|
||
|
var _self = this
|
||
|
if (_self.data.audioFile.isPlay) {
|
||
|
audioContext.stop()
|
||
|
} else {
|
||
|
audioContext.src = _self.data.audioFile.path
|
||
|
audioContext.autoplay = true
|
||
|
}
|
||
|
audioContext.onCanplay((res) => {
|
||
|
if (_self.data.waitFlag) {
|
||
|
audioContext.play()
|
||
|
_self.setData({
|
||
|
waitFlag: false
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
audioContext.onPlay((res) => {
|
||
|
_self.data.audioFile.isPlay = true
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile
|
||
|
})
|
||
|
})
|
||
|
audioContext.onStop((res) => {
|
||
|
_self.data.audioFile.isPlay = false
|
||
|
_self.data.audioFile.curDuration = 0
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile,
|
||
|
curTimeStr: '00:00'
|
||
|
})
|
||
|
})
|
||
|
audioContext.onEnded((res) => {
|
||
|
_self.data.audioFile.isPlay = false
|
||
|
_self.data.audioFile.curDuration = 0
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile,
|
||
|
curTimeStr: '00:00'
|
||
|
})
|
||
|
})
|
||
|
audioContext.onError((res) => {
|
||
|
_self.data.audioFile.isPlay = false
|
||
|
_self.data.audioFile.curDuration = 0
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile,
|
||
|
curTimeStr: '00:00'
|
||
|
})
|
||
|
})
|
||
|
audioContext.onSeeking(() => {
|
||
|
console.log(audioContext.currentTime)
|
||
|
})
|
||
|
audioContext.onWaiting(() => {
|
||
|
audioContext.pause()
|
||
|
_self.setData({
|
||
|
waitFlag: true
|
||
|
})
|
||
|
})
|
||
|
audioContext.onTimeUpdate(() => {
|
||
|
_self.data.audioFile.curDuration = parseInt(audioContext.currentTime)
|
||
|
_self.data.audioFile.duration = parseInt(audioContext.duration)
|
||
|
var curM = parseInt(audioContext.currentTime / 60) //分钟
|
||
|
var curS = parseInt(audioContext.currentTime % 60) //秒
|
||
|
var tM = parseInt(audioContext.duration / 60) //分钟
|
||
|
var tS = parseInt(audioContext.duration % 60) //秒
|
||
|
var curMStr = curM > 9 ? curM : '0' + curM
|
||
|
var curSStr = curS > 9 ? curS : '0' + curS
|
||
|
var totalMStr = tM > 9 ? tM : '0' + tM
|
||
|
var totalSStr = +tS > 9 ? tS : '0' + tS
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile,
|
||
|
curTimeStr: curMStr + ':' + curSStr,
|
||
|
totalTimeStr: totalMStr + ':' + totalSStr
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
//倒退5秒
|
||
|
rewind() {
|
||
|
var _self = this
|
||
|
if (_self.data.audioFile.isPlay) {
|
||
|
_self.data.audioFile.curDuration = _self.data.audioFile.curDuration - _self.data.speedStep
|
||
|
audioContext.seek(_self.data.audioFile.curDuration)
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile
|
||
|
})
|
||
|
}
|
||
|
|
||
|
},
|
||
|
//快进5秒
|
||
|
speed() {
|
||
|
var _self = this
|
||
|
if (_self.data.audioFile.isPlay) {
|
||
|
_self.data.audioFile.curDuration = _self.data.audioFile.curDuration + _self.data.speedStep
|
||
|
audioContext.seek(_self.data.audioFile.curDuration)
|
||
|
_self.setData({
|
||
|
audioFile: _self.data.audioFile
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
slider4change(e) {
|
||
|
if (this.data.audioFile.isPlay) {
|
||
|
audioContext.seek(e.detail.value)
|
||
|
}
|
||
|
}
|
||
|
})
|