错误1 发送没有反应,觉得是地址不对,老师上课有改,但是找不到。
查了以前的是mui.post处,但是是window.serv,本以为是系统自动检测,
但是也不可能是监测到9527吧,
从网上https://www.cnblogs.com/wen-kang/p/10778812.html博客里找到:
为了避免hbuilder中的js频繁的给后端发送AJAX,更换ip,可以将ip设置为全部变量,在引用文件的js文件添加代码如下:
window.serv="http://192.168.1.114:9527";
extras:{
.....//自定义扩展参数,可以用来处理页面间传值
},
前端的音乐播放的哪里的资源?
数据库里没有给传过去MP3!
<button type="button" class="mui-btn mui-btn-green mui-btn-block" id="resume">继续</button>
var Sdata = null; #通过plus.webview可获取应用界面管理对象。
Sdata = plus.webview.currentWebview(); #获取当前窗口的WebviewObject对象
document.getElementById("title").innerText = "正在播放 " + Sdata.title;
ap = plus.audio.createPlayer(window.music_serv + Sdata.music); # 括号里的‘xx.MP3’从哪里来 ‘http://192.168.12.70:9527/get_music/’
ap.play();
document.getElementById('resume').addEventListener('tap', function() {
ap.resume();
});
mui.js 里有配置参数
window.serv = "http://192.168.12.70:9527";
window.ws_serv = "ws://192.168.12.70:9527/app/";
window.image_serv = window.serv + "/get_cover/";
window.music_serv = window.serv + "/get_music/";
播放的是 这里的 send_file
@content_bp.route('/get_music/<filename>',methods=['GET'])
def get_music(filename):
music_path = os.path.join(MUSIC_PATH, filename)
return send_file(music_path)
数据如下:应该是data.DATA data是 auto.login 传过来的数据 fuc(data)
[{"_id":"5d32b0839c057a77211fad55","cover":"c6b68f04-9a4c-46b6-9560-0bb31c38c7b7.jpg","music":"c6b68f04-9a4c-46b6-9560-0bb31c38c7b7.mp3","title":"新年恰恰","zhuanji":"【一千零一夜】经典儿歌"},..........{"_id":"5d32b0839c057a77211fad68","cover":"17e969d0-6e37-4438-a877-e2240e191984.jpg","music":"17e969d0-6e37-4438-a877-e2240e191984.
stada.music : "music":"c6b68f04-9a4c-46b6-9560-0bb31c38c7b7.mp3"
sdata的值 plus.webview.currentWebview();?不是等于创建一个窗口吗?
{"__view_array__":[],"__IDENTITY__":"NWindow","__uuid__":"NWindow91563607904411","__callbacks__":{"back":[null],"menu":[null]},"__callback_id__":"plus41563607905521","id":"player.html","music":"c6b68f04-9a4c-46b6-9560-0bb31c38c7b7.mp3","title":"新年恰恰","cover":"c6b68f04-9a4c-46b6-9560-0bb31c38c7b7.jpg","zhuanji":"【一千零一夜】经典儿歌","_id":"5d32b0839c057a77211fad55"} at player.html:58
访问这个网址,就可以播放音乐,后端开启的状态下。这里面存了send_file的MP3
http://192.168.12.70:9527/get_music/e87e08f5-28e9-493f-8f5a-15ef02d3abc6.mp3
所以
ap = plus.audio.createPlayer(window.music_serv + Sdata.music); 'h://..xx.mp3'
就可以播放了(没有点击事件,只不过是后端传到网络上的资源)
Sdata
console.log('sdata:', Sdata)---> sdata: at player.html:49 是这个?
注册
@user_bp.route("/reg", methods=["POST"])
def reg():
user_info = request.form.to_dict()
print('注册')
print(user_info)
user_info["avatar"] = "baba.jpg" if user_info.get("gender") == "2" else "mama.jpg"
user_info["bind_toys"] = []
user_info["friend_list"] = []
MDB.Users.insert_one(user_info)
return jsonify({"CODE":0,"MSG":"注册成功","DATA":{}})
登录
@user_bp.route("/login", methods=["POST"])
def login():
print('登录')
print(request.form, type(request.form))
user_info = request.form.to_dict()
print(user_info.get('_id'))
print(user_info, type(user_info))
user_info_dict = MDB.Users.find_one(user_info)
user_info_dict["_id"] = str(user_info_dict.get("_id"))
print('登录')
RET["CODE"] = 0
RET["MSG"] = f"欢迎{user_info_dict.get('nickname')}登录"
RET["DATA"] = user_info_dict
return jsonify(RET)
自动登录
@user_bp.route("/auto_login",methods=["POST"])
def auto_login():
print('自动登录')
user_info = request.form.to_dict()
print('原来', user_info.get('_id'), type(user_info.get('_id'))) # 原来 5d32b21dbd7107c6ea54c890 <class 'str'>
user_info["_id"] = ObjectId(user_info.get("_id"))
print('之后', user_info['_id'], type(user_info['_id'])) # 之后 5d32b21dbd7107c6ea54c890 <class 'bson.objectid.ObjectId'>
user_info_dict = MDB.Users.find_one(user_info) # 字符串怎么不行呢? 因为是_id ,之前的是自动生成的,这一次是给他值
# 默认格式是 '_id' : ObjectId('5d32b21dbd7107c6ea54c890') 而不是 5d32b21dbd7107c6ea54c890 的格式
print('自动登录')
user_info_dict["_id"] = str(user_info_dict.get("_id"))
RET["CODE"] = 0
RET["MSG"] = f"欢迎{user_info_dict.get('nickname')}登录"
RET["DATA"] = user_info_dict
print(RET)
return jsonify(RET)