123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- var isEdit;
- var articleId;
-
- mui.plusReady(function() {
- var self = plus.webview.currentWebview();
- isEdit = self.isEdit;
- articleId = self.articleId;
- getArticleDetail();
- bindEvents();
- })
- //获取文章详情
- function getArticleDetail() {
- sendPost("/third/jkEdu/Article/getArticalById",{articleId:articleId, userType: 1}, null, function(res){
- if(res.status == 200){
- if(res.data.isAuthentication == 0){
- $("#isEdit").show();
- }else{
- $("#isEdit").hide();
- }
- var content = res.data.articleContent;
- var reg=/group1\//g;
- content = content.replace(reg,imgUrlDomain+ 'group1/');
-
- var html=template("articleDetail_tmpl", {it: res.data, content: content});
- $("#mainContent").html(html);
- //禁止超链接执行默认行为
- $("#mainContent a").attr("onclick","return false");
- }else{
- queryFailed(res);
- }
- },'get')
- }
- function queryFailed(res){
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("加载文章失败!");
- }
- }
- function bindEvents(){
- $("#main").on("click",".collection",function(){
- var status = $(this).attr("data-status");
- if(status==0){
- collectionArticle($(this))
- }else{
- unCollectionArticle($(this))
- }
- return;
- });
- $("#main").on("click",".share",function(){
- var $this = $(this);
- var articleId = $this.attr("data-code");
- var articleTitle = $this.attr("data-title");
- mui.openWindow({
- id: "xuanzejumin_more",
- url: "xuanzejumin_more.html",
- extras: {
- articleId:articleId,origin:'jiaoyu',articleTitle:articleTitle
- }
- })
- });
- $("#isEdit").click(function() {
- mui.openWindow({
- id: "article-edit",
- url: "article-edit.html",
- extras: {
- articleId:articleId
- }
- })
- });
-
- //为文章内的超链接监听点击事件
- $("#mainContent").on('click', "a", function(){
- var $this = $(this),
- url = $this.attr("href");
- mui.openWindow({
- id: "browser-page",
- url: "../../browser/html/browser.html",
- extras: {
- url: url
- }
- })
- })
- }
- function collectionArticle($this){
- plus.nativeUI.showWaiting();
- var params = {};
- params.articleId=articleId;//文章id
- params.userType=1;//1是医生 2是居民
- sendPost("/third/jkEdu/Article/saveArticleCollection",params,function(res){
- plus.nativeUI.closeWaiting();
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("收藏失败!");
- }
- },function(res){
- plus.nativeUI.closeWaiting();
- if(res.status==200){
- $this.attr("data-status", 1);
- $this.find("img").attr("src", "../images/shoucang_pre.png");
- var span = $this.find("span");
- span.html("已收藏");
- plus.nativeUI.toast("收藏成功");
- resPage();
- }else{
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("收藏失败!");
- }
- }
-
- })
- }
- function unCollectionArticle($this){
- plus.nativeUI.showWaiting();
- var params = {};
- params.articleId=articleId;//文章id
- params.userType=1;//1是医生 2是居民
- sendPost("/third/jkEdu/Article/cancelArticleCollection",params,
- function(res){
- plus.nativeUI.closeWaiting();
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("取消收藏失败!");
- }
- },
- function(res){
- plus.nativeUI.closeWaiting();
- if(res.status==200){
- $this.attr("data-status", 0);
- $this.find("img").attr("src", "../images/shoucang_button.png");
- var span = $this.find("span");
- span.html("收藏");
- plus.nativeUI.toast("取消收藏成功");
- resPage();
- }else{
- if(res.msg){
- plus.nativeUI.toast(res.msg);
- }else{
- plus.nativeUI.toast("取消收藏失败!");
- }
- }
-
- })
- }
- function resPage(){
- var view = plus.webview.getWebviewById("jiankangjiaoyu");
- if(view){
- mui.fire(view,"refresh");
- }
- var my_store = plus.webview.getWebviewById("my_store");
- if(my_store){
- mui.fire(my_store,"refresh");
- }
- }
- template.helper('setTimer',function(o){
- return o.substr(0,19)
- });
|