新增SpringSecurity来认证

新增音乐分享功能
修改跨域代码
http工具改为同步
This commit is contained in:
2021-10-23 13:03:45 +08:00
parent 90af00b235
commit 98da63a0d5
16 changed files with 779 additions and 217 deletions

View File

@@ -55,6 +55,7 @@
<script type="text/html" id="music">
<a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
<a class="layui-btn layui-btn-xs" lay-event="play">播放</a>
<a class="layui-btn layui-btn-xs" lay-event="share">分享</a>
</script>
<script>
let localhost = "";
@@ -62,24 +63,33 @@
let isRandom = true;
let playIndex = 0;
let playNow = ""
$.get("/nas/music/getlocalhost.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk", function (obj) {
let share=getParam('share');
if(share!=null){
$('#playlist').remove()
$('#reload').remove()
$('#next').remove()
}
$.get("/nas/music/getlocalhost.do",{share:share}, function (obj) {
try {
let json = JSON.parse(obj);
localhost = json.data + ":8000";
console.log("音频地址:" + localhost)
if(json.code===403){
layer.msg('您没有权限访问')
return;
}
localhost = json.data ;
if (localhost === 'http://null:8000' || localhost === ":8000") {
localhost = "http://127.0.0.1"
localhost = "http://"+window.location.host;
}
} catch (e) {
localhost = ""
console.log(e)
}
localhost = "http://120.55.85.10:8001";
layui.use(['table', 'element'], function () {
let table = layui.table;
let element = layui.element;
let listTable = table.render({
elem: '#playlist'
, url: localhost + '/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk' //数据接口
, url: localhost + '/nas/music/list.do?token=' //数据接口
, method: 'post'
, where: {
path: 'root',
@@ -91,9 +101,9 @@
{field: 'title', title: '标题', width: 400, sort: true, templet: "#listTemplet"}
, {field: 'artist', title: '艺术家', width: 200}
, {field: 'album', title: '专辑', width: 200}
, {field: 'composer', title: '作曲', width: 200}
, {field: 'composer', title: '作曲', width: 150}
, {field: 'track', title: '音轨号', width: 100, sort: true}
, {field: "right", width: 150, toolbar: '#music'}
, {field: "right", width: 200, toolbar: '#music'}
]]
, done: function (res, curr, count) {
musicLib = res.data
@@ -101,6 +111,7 @@
}
})
table.on('rowDouble(music)', function (obj) {
console.log("双击:"+obj)
//obj 同上
if (obj.data.isdir === 1) {
listTable.reload({
@@ -123,7 +134,7 @@
let data = obj.data;
if (obj.event === 'download') {
if (data.isdir === 0) {
window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + new Base64().encode(data.file))
window.open(localhost + "/nas/music/play.do?token=&random=false&filePath=" + new Base64().encode(data.file))
}
} else if (obj.event === 'play') {
$.ajax({
@@ -151,6 +162,15 @@
}
})
}else if(obj.event==='share'){
$.post('/nas/music/share.do',{file:data.file},function (json){
if(json.code===0){
layer.prompt({
title:"分享链接",
value:"http://"+window.location.host+"/html/body/nas/music.html?share="+json.data.token
})
}
})
}
});
element.on('nav(menus)', function (elem) {
@@ -183,11 +203,14 @@
$('#footer').load("/html/footer.html");
$('#side').load("/html/body/nas/side.html");
$('#img').click(function () {
if(share!==null){
return;
}
isRandom = true;
random()
});
$('#download').click(function () {
window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + playNow)
window.open(localhost + "/nas/music/play.do?token=&random=false&filePath=" + playNow)
});
$('#next').click(function () {
playNext()
@@ -222,7 +245,7 @@
if (json.code === 0) {
playNow = json.data
player.updateSource({
source: localhost + "/nas/music/play.do?random=false&filePath=" + json.data + "&token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk"
source: localhost + "/nas/music/play.do?random=false&filePath=" + json.data
});
update(json.data)
player.play()
@@ -236,8 +259,9 @@
function play(file) {
let filePath = escape(new Base64().encode(file))
playNow = filePath
console.log(localhost + "/nas/music/play.do?random=false&filePath=" + filePath )
player.updateSource({
source: localhost + "/nas/music/play.do?random=false&filePath=" + filePath + "&token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk"
source: localhost + "/nas/music/play.do?random=false&filePath=" + filePath
});
update(filePath)
player.play()
@@ -280,7 +304,17 @@
})
$('#img').attr("src",localhost+'/nas/music/web/image.do?fileName='+fileName);
}
function playShare(){
console.log("播放分享:"+share)
$.get('/nas/music/playShare.do?share='+share,function (json) {
isRandom = false;
playIndex =0;
play(json.data)
})
}
if(share!==null){
playShare()
}
</script>
<style>