diff --git a/js/notepad.js b/js/notepad.js index b9bdc5c..4afc9bd 100644 --- a/js/notepad.js +++ b/js/notepad.js @@ -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 ++ ; - }else{ - mui.toast("开发中") - this.counter = 0; - JZL.openWindow('trade_rule.html', 'trade_rule.html') - } + 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.alert(res.msg); + } + }, + error: function(err){ + mui.alert("请求失败"); + self.back(); + } + }); + }, + }, + created() { + var localData = localStorage.getItem("LOCAL_NOTE"); + this.loadData(); + if(localData){ + this.noteData = JSON.parse(localData); } }, - 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"}, - ] - } }) \ No newline at end of file diff --git a/js/notepad_edit.js b/js/notepad_edit.js new file mode 100644 index 0000000..b8464ee --- /dev/null +++ b/js/notepad_edit.js @@ -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(); + } + }) + + }) +}) diff --git a/js/trade_rule.js b/js/trade_rule.js index 31ce60a..135830a 100644 --- a/js/trade_rule.js +++ b/js/trade_rule.js @@ -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); + } + }, + error: function(err){ + mui.alert("请求失败"); + self.back(); + } + }); } }, - 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"}, - ] + created() { + var localData = localStorage.getItem("LOCAL_RULE"); + this.loadData(); + if(localData){ + this.noteData = JSON.parse(localData); + } } }) \ No newline at end of file