1 Star 0 Fork 17

梁铭钊/wmusic

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 2.83 KB
一键复制 编辑 原始数据 按行查看 历史
//app.js
App({
onLaunch: function () {
var autodown = wx.getStorageSync(this.key.isAutoDown),
autoplay = wx.getStorageSync(this.key.isAutoPlay);
if(typeof autodown == 'undefined' || ('' + autodown) == ''){ wx.setStorageSync(this.key.isAutoDown, true) }
if(typeof autoplay == 'undefined' || ('' + autoplay) == ''){ wx.setStorageSync(this.key.isAutoPlay, true) }
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
})
}
},
globalData:{
userInfo:null
},
recordPlayInfo : function(info){
/*
{
type:{
hash : { //hash码
num : 1, // 播放次数
singername : '歌手',
songname : '歌名',,
alum : '专辑/照片',
loc_alum : '本地',
url : '播放地址',
loc_url : '本地地址',
lasttime : 1000 //最后一次播放时间
}
},
type :{}
}
*/
var that = this,data = wx.getStorageSync(that.key.recordPlayInfo);
if(data == ''){ data = {}; }
var _type = data[info.type] || {},_info = _type[info.hash];
if(typeof _info == 'undefined'){
info.num = 1;
_info = info;
}else{
for(var key in info){ _info[key] = info[key]; }
_info.num = (_info.num || 1 ) + 1;
}
if(typeof data[info.type] === 'undefined'){ data[info.type] = {}; }
data[info.type][info.hash] = _info;
wx.setStorage({ key : that.key.recordPlayInfo , data : data});
}
,getPlayInfos : function(cb){
if(typeof cb == "function"){
var info = wx.getStorageSync(this.key.recordPlayInfo);
cb(info == '' ? {} : info);
}
}
,getLastPlayInfo : function(cb){
var that = this;
if(typeof cb == "function"){
var info = wx.getStorageSync(that.key.lastPlayInfo);
cb(info == '' ? {} : info);
}
},
setLastPlayInfo : function(info){
var that = this;
this.getLastPlayInfo(function(res){
for(var key in info){
res[key] = info[key];
}
wx.setStorageSync(that.key.lastPlayInfo,res);
});
},
key : {
//是否自动下载
isAutoDown : '_is_autodown'
,isAutoPlay : '_is_autoplay'
,lastPlayInfo: '_last_playinfo'
,recordPlayInfo : '_record_play_info'
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
微信
1
https://gitee.com/liang-mingzhao/wmusic.git
git@gitee.com:liang-mingzhao/wmusic.git
liang-mingzhao
wmusic
wmusic
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385