对接接口

This commit is contained in:
Jerry Yan 2020-05-25 22:03:54 +08:00
parent 64872b2e78
commit dbc607f67d
3 changed files with 140 additions and 35 deletions

View File

@ -1,21 +1,17 @@
mui.plusReady(function(){
// some ajax
$(".footer").on("tap", ()=>{
app.create()
$(".footer").click(function(){
app.create();
})
})
const app = new Vue({
el: '#app',
data() {
return {
noteData: [
],
counter: 0
}
},
created() {
console.log("Vue")
},
methods: {
triggerDelete(index) {
this.$set(this.noteData[index], 'currentDelete', true)
@ -30,28 +26,49 @@ const app = new Vue({
window.location.reload()
},
edit(index){
console.log("编辑", this.noteData[index])
// some ajax
mui.toast("编辑")
window.location.reload()
mui.openWindow({
url: "notepad_edit.html",
id: "notepad_edit"+index,
extras: {
noteId: index
},
createNew: false, //是否重复创建同样id的webview默认为false:不重复创建,直接显示
waiting: {
autoShow: true, //自动显示等待框默认为true
title: '正在加载...', //等待对话框上显示的提示内容
}
})
},
create(){
// some jump
if(this.counter < 10){
mui.toast("跳转")
this.counter ++ ;
this.edit(0);
// JZL.openWindow('trade_rule.html', 'trade_rule.html')
},
loadData() {
$.ajax({
url: qlgUrl("app/note/index"),
method: "GET",
dataType: 'json',
success: function(res){
if(res.status == 1){
this.noteData = res.data;
localStorage.setItem("LOCAL_NOTE", JSON.stringify(res.data));
}else{
mui.toast("开发中")
this.counter = 0;
JZL.openWindow('trade_rule.html', 'trade_rule.html')
}
mui.alert(res.msg);
}
},
mounted() {
// some ajax
this.noteData = [
{id: 1, name: '功能正在开发中', created_at: "2019-09-09 18:00:01", updated_at: "2019-09-09 18:09:09"},
{id: 2, name: '只是一个DEMO页', created_at: "2019-09-09 19:00:01", updated_at: "2019-09-09 20:09:09"},
]
error: function(err){
mui.alert("请求失败");
self.back();
}
});
},
},
created() {
var localData = localStorage.getItem("LOCAL_NOTE");
this.loadData();
if(localData){
this.noteData = JSON.parse(localData);
}
},
})

72
js/notepad_edit.js Normal file
View File

@ -0,0 +1,72 @@
mui.init({
beforeback: function() {
//获得父页面的webview
var list = plus.webview.currentWebview().opener(); //触发父页面的自定义事件(refresh),从而进行刷新
list.reload();
//返回true,继续页面关闭逻辑
return true;
}
});
mui.plusReady(function(){
window.self = plus.webview.currentWebview();
var Id = self.noteId;
var E = window.wangEditor
window.editor = new E('#content')
editor.customConfig.qiniu = true;
editor.customConfig.debug = true;
editor.create();
var $createTime = $("#createTime");
var $title = $("#title");
if(Id == 0) {$createTime.text("现在");}
else {
$.ajax({
url: qlgUrl("app/note/detail"),
method: "GET",
data: {
id: Id,
},
dataType: "json",
success: function(res){
console.log(res);
if(res.status == 1){
$createTime.text(res.data.create_time);
$title.val(res.data.title);
editor.txt.html(res.data.content);
}else{
alert(res.msg);
self.back();
}
},
error: function(err){
alert("请求失败");
self.back();
}
})
}
$(".footer").on("tap", function(){
var title = $title.val();
var content = editor.txt.html();
$.ajax({
url: qlgUrl("app/note/save"),
method: "POST",
data: {
id: Id,
title: title,
content: content,
},
dataType: "json",
success: function(res){
if(res.status != 1){
mui.alert(res.msg);
}else{
mui.back();
}
},
error: function(err){
mui.alert("请求失败");
self.back();
}
})
})
})

View File

@ -9,20 +9,36 @@ const app = new Vue({
]
}
},
created() {
console.log("Vue")
},
methods: {
detail(index){
console.log(this.ruleData[index])
// some jump
},
loadData(){
$.ajax({
url: qlgUrl("app/trade_rule/index"),
method: "GET",
dataType: 'json',
success: function(res){
if(res.status == 1){
this.ruleData = res.data;
localStorage.setItem("LOCAL_RULE", JSON.stringify(res.data));
}else{
mui.alert(res.msg);
}
},
mounted() {
// some ajax
this.ruleData = [
{id: 1, name: '这个是个开发中的页面呢', announced_at: "2019-09-09 18:09:01"},
{id: 2, name: '待我来继续开发呢', announced_at: "2019-09-09 19:09:01"},
]
error: function(err){
mui.alert("请求失败");
self.back();
}
});
}
},
created() {
var localData = localStorage.getItem("LOCAL_RULE");
this.loadData();
if(localData){
this.noteData = JSON.parse(localData);
}
}
})