Code Monkey home page Code Monkey logo

chaoxing-source's People

Contributors

rabbit-tian avatar

Watchers

 avatar

chaoxing-source's Issues

8. 学习通收藏和取消收藏

  1. 收藏

             jsBridge.postNotification("CLIENT_SUBSCRIBE_RES", {
               cataid: "100000015",
               cataName: "网址",
               key: activeSign,
               content: {
                 toolbarType: 2,
                 resTitle: title,
                 resUrl: methodFn.commonUrl + "1-02active.html?id=" + activeId,
                 resUid: puid,
                 resLogo: activeSrc
               }
             });
    
             try {
               jsBridge.bind("CLIENT_SUBSCRIBE_RES", function (object) {
                 // 成功打开后,发送ajax请求 ,收藏此活动
                 if (object.status) {
                   $.ajax({
                     // url: methodFn.dataUrl + "/activity/save_page?fid=1385&uid=52379735",
                     url: methodFn.dataUrl + "/activity/save_page",
                     method: "post",
                     dataType: "json",
                     data: {
                       fid: fid,
                       uid: puid,
                       id: id
                     },
                     success: function (data) {
                       if (data.status) {
                         $("#collect img").attr("src", "/img/red-heart.png");
                         $("#collect span").text("取消收藏");
                         isSave = 1;
                       }
                     },
                     error: function () { }
                   });
                 }
               });
             } catch (e) { }
    
  2. 取消收藏

             // 取消收藏
             jsBridge.postNotification("CLIENT_REMOVE_RES", {
               cataid: "100000015",
               key: activeSign
             });
    
             try {
               jsBridge.bind("CLIENT_REMOVE_RES", function (object) {
                 // alert(JSON.stringify(object));
                 if (object.status) {
                   $.ajax({
                     // url: methodFn.dataUrl + "/activity/del_page?fid=1385&uid=52379735",
                     url: methodFn.dataUrl + "/activity/del_page?",
                     method: "post",
                     dataType: "json",
                     data: {
                       fid: fid,
                       uid: puid,
                       id: id
                     },
                     success: function (data) {
                       if (data.status) {
                         $("#collect img").attr("src", "/img/white-heart.png");
                         $("#collect span").text("收藏");
                         isSave = 0;
                       }
                     },
                     error: function () { }
                   });
                 }
               });
             } catch (e) { }
    
    

11. 查看是否在 app 端登录

var sharebacktype = null;
var tipUrl = null;
if (dealVersion(getXxtVersion()) >= dealVersion("3.1.2.1")) {
  sharebacktype = 7;
} else {
  $(".mark").show();
  sharebacktype = 1;
}

// 填写跳转的地址
resourceUrl = 'http://www.chaoxing.com';

var appScheme =
  "chaoxingshareback://url=" +
  encodeURIComponent(resourceUrl) +
  "&title=" +
  encodeURIComponent("运动排行") +
  "&sharebacktype=" +
  sharebacktype;
tipUrl =
  "http://zhuanti.chaoxing.com/special/course/tips?apptag=1000&appScheme=" +
  encodeURIComponent(appScheme);
//如果是ios
if (isIos()) {
  //如果版本大于等于IOS9
  var iosVersion = getIOSVersion();
  if (iosVersion >= 9) {
    tipUrl =
      "http://share1.chaoxing.com/mobile/mooc/tocourse/90394356?sharebacktype=" +
      sharebacktype +
      "&appScheme=" +
      encodeURIComponent(appScheme) +
      "&title=&apptag=1000&url=" +
      encodeURIComponent(resourceUrl);
  }
}

$("#btn").click(function() {
  document.location.href = tipUrl;
});

6. 学习通分享

                $(".share")
                  .off("touchstart")
                  .on("touchstart", function () {
                    share(
                      title,
                      methodFn.commonUrl +
                      "1-02active.html?id=" +
                      activeId,
                      "随手拍,视频,小程序"
                    );
                  });

                function share(aa, bb, cc) {
                  resUrl = bb;
                  var content = {
                    resTitle: aa,
                    resUrl: resUrl,
                    resUid: cc,
                    toolbarType: 2
                  };
                  if (resUrl != null && resUrl != "") {
                    jsBridge.postNotification("CLIENT_TRANSFER_INFO", {
                      cataid: 100000015,
                      content: content
                    });
                  }
                }

9. 学习通视频播放

        function videoTrigger() {
          $(".video-trigger").on("click", function () {
            if ($(this).attr('isVideo')) {
              jsBridge.postNotification("CLIENT_VIDEO_PLAYER", {
                videolist: [
                  {
                    videopathm3u8: $(this).data("m3u8"),
                    videopathmp4: $(this).data("mp4"),
                    title: $(this).data("title")
                  },
                  {
                    videopathm3u8: $(this).data("m3u8"),
                    videopathmp4: $(this).data("mp4"),
                    title: $(this).data("title")
                  }
                ],
                title: $(this).data("title")
              });
            }
            //隐藏学习通中白色顶部
            AppUtils.hideToolbar({
              toolbarType: "0"
            });
          });
        }


2. common.js 的使用

  1. 请求地址
  • var methodFn = new activityApp.activity(); // 数据请求 链接
  1. 具体使用
  • 图片地址: methodFn.imgUrl
  • 头像地址: methodFn.photourl
  • 数据地址: methodFn.dataUrl
  • 页面跳转地址: methodFn.projectUrl

1. 使用前需要 的一些依赖文件

  1. <script src="/js/mobileVersion.js"></script>
  2. <script src="/js/common.js"></script>
  3. <script src="/js/base.js"></script>
  4. <script src="/js/CXJSBridge.js"></script>
  5. <script src="/js/app.utils.js"></script>

简单介绍:

  1. mobileVersion.js

    • ios和安卓头部的适配
  2. common.js

    • 对一些公司数据接口 和 图片接口 链接的封装,常用函数工具的封装
  3. base.js

    • 用户登录,获取 fid,uid 等
  4. js/CXJSBridge.js

  5. app.utils.js

    • 退出客户端、退回到首页、打开语音识别...等功能函数封装

下拉刷新协议使用

  1. 使用插件 - pulltorefresh.js
  2. 具体使用例子
       function PullRefresh() {
         ptr = PullToRefresh.init({
           mainElement: "#work", // above which element?
           onRefresh: function () {
             $load.css({ visibility: "visible" }); // loading图
             $.ajax({
               // url: methodFn.dataUrl + "/work/page?fid=1385&UID=52379735",
               url: methodFn.dataUrl + "/work/page?",
               method: "post",
               dataType: "json",
               data: {
                 fid: fid,
                 uid: puid,
                 index: 0, // 只请求 第一页数据就可
                 pageSize: counts,
                 activityId: activeId
               },
               success: function (data) {
                 // console.log(data);
                 if (data.status) {
                   var list = data.info.list;
    
                   if (Utils.isArray(list)) {
                     // 加载数据 索引
                     // workIndex += counts;
    
                     var htmlwork = workHtml(list);
    
                     $("#no-data").hide();
                     $work.html(htmlwork);
    
                     // 计算标题的高度 显示完全与否
                     titleHiehgt();
    
                     // 初始化 轮播图
                     for (var i = 0; i < swiperArr.length; i++) {
                       var swiper = new Swiper(".swiper-container" + swiperArr[i], {
                         slidesPerView: 3
                       });
                     }
    
                     // 初始化视频播放器
                     videoTrigger();
    
                     // 点赞
                     $load.css({
                       visibility: "hidden"
                     }); // loading图
                     scrollOnOff = true;
                     // 初始化 - 长按
                     $(".part").each(function (e) {
                       HammerInit($(this)[0]);
                     });
    
                     // 如果已经请求的条数 加上将要 请求的 条数 大于 数据总条数,说明没有数据了
                     if (data.info.index + data.info.pageSize >= data.info.counts) {
                       $work.append(
                         '<div class= "no-more"> 没有更多数据了...</div>'
                       );
                       $(window).off("scroll");
                     } else {
                       // 懒加载
                       winScrolld();
                     }
    
                     // }, 1000);
                   } else {
                     //  没有数据
                     $(".load").css({
                       visibility: "hidden"
                     });
    
                     // 如果第一次就没有数据,  就显示无数据内容
                     if (workIndex === 0) {
                       $("#no-data").show();
                       if (
                         stau == "已结束" ||
                         stau == "已过期" ||
                         stau == "未开始"
                       ) {
                         $(".publish-now").hide();
                       }
                     }
                   }
                 }
               },
               error: function () {
                 $("#work-fail").text("请稍后重试");
                 $("#work-fail").show();
                 setTimeout(function () {
                   $("#work-fail").hide();
                 }, 1000);
               }
             });
           }
         });
       }
    

laydate 时间日历

  1. 可以禁选当前日期前的时间
<input type="text" placeholder="请选择日期"  id="test">

     laydate.render({
       elem: '#test',//指定元素
        min: timeChangeSelect(+new Date,3), // 最小时间限制
         max: '2019-12-31', // 最大时间限制
    });
    // 时间戳转换
      function timeChangeSelect(time, num) {
        var date = new Date(Number(time));
        Y = date.getFullYear();
        M = double(date.getMonth() + 1);
        D = double(date.getDate());
        h = double(date.getHours());
        m = double(date.getMinutes());
        s = double(date.getSeconds());

        if (num === 0) {
          return Y + "." + M + "." + D + " " + h + ":" + m;
        } else if (num === 1) {
          return Y + "." + M + "." + D;
        } else if (num === 2) {
          return m + ":" + s;
        }else if (num == 3) {
          return Y + "-" + M + "-" + D;
        } 

        // 时间补零操作
        function double(time) {
          return time < 10 ? "0" + time : time + "";
        }
      }

请求数据的参数中 特殊符号的 处理

//判断特殊表情符号
function isEmojiCharacter(substring) {
	for(var i = 0; i < substring.length; i++) {
		var hs = substring.charCodeAt(i);
		if(0xd800 <= hs && hs <= 0xdbff) {
			if(substring.length > 1) {
				var ls = substring.charCodeAt(i + 1);
				var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
				if(0x1d000 <= uc && uc <= 0x1f77f) {
					return true;
				}
			}
		} else if(substring.length > 1) {
			var ls = substring.charCodeAt(i + 1);
			if(ls == 0x20e3) {
				return true;
			}
		} else {
			if(0x2100 <= hs && hs <= 0x27ff) {
				return true;
			} else if(0x2B05 <= hs && hs <= 0x2b07) {
				return true;
			} else if(0x2934 <= hs && hs <= 0x2935) {
				return true;
			} else if(0x3297 <= hs && hs <= 0x3299) {
				return true;
			} else if(hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 ||
				hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b ||
				hs == 0x2b50) {
				return true;
			}
		}
	}
}

10. 学习通 图片查看

    function seeImg() {
        var op = {"showIndex":0,"imageUrls":[{"imageUrl":"http://p.ananas.chaoxing.com/star3/origin/56f22bd4e4b0578413c5d02e.jpg?rw=640&rh=182"},{"imageUrl":"http://img1.16q.cn/a56626a15a1c2cc92d0b0972e3d086ba"},{"imageUrl":"http://www.baidu.com/img/bd_logo1.png"}] };
        // var op = { "showIndex": 0, "imageUrls": [{ "imageUrl": "http://mobile.ctld.chaoxing.com/certificate/5166546242.png?t=123" }] };
        jsBridge.postNotification('CLIENT_PREVIEW_IMAGES', op);
      }

4. 学习通返回协议

    // 返回
     $("#link-to").on("touchstart", function () {
       jsBridge.postNotification("CLIENT_REFRESH_STATUS", { status: 1 });
       jsBridge.postNotification("CLIENT_EXIT_LEVEL", {});
     });

7. 学习通-交流小组

                // 加入 并 跳转到交流小组
                $("#chat").on("touchstart", function () {
                  // alert(circleId)
                  addGroup1();
                  jsBridge.postNotification("CLIENT_OPEN_GROUP", {
                    GroupId: circleId,
                    Groupbbsid: circleId,
                    needRecord: "…"
                  });
                });

                function addGroup1() {
                  try {
                    jsBridge.postNotification("CLIENT_ADDTO_GROUP", {
                      groupInfo: '{"id": ' + circleId + ',"isCheck":0}',
                      uid: puid
                    });
                  } catch (e) { }
                }


文本框中 字数控制

/**
 * @ 功能:字数控制 
 * @ 参数:str:要控制的字符串,max:字数上限
 */
function fontControl(elem, max) {
	let val = elem.val();
	let leng = Math.round(getByteLength(val) / 2);
	if(leng > max) {
		if(val.replace(/[^\u0-\u80]/gi, "")) { //判断是否包含非汉字字符
			let CLength;
			CLength = val.match(/[^\u0-\u80]/gi).length; //输入框中值汉字的长度
			//计算当输入的值包含除汉字外的字符时,一个汉字算1,两个非汉字字符算1前提下的maxlength值(此公式无逻辑,是简化后的式子)
			max = 2 * max - CLength;
		}
		elem.val( val.substr(0, max) );
		showPrompt("作品介绍只能输入500个字!");
	}
}
$(".title").on("input propertychange",function(){
	fontControl($(this), 500);
});

3. 学习通页面之间跳转 协议

  1. 搜索页跳转链接

     $("#activ-search").on("touchstart", function () {
         openA('', methodFn.projectUrl + "1-18search.html?activityId=" + activeId);
      });
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.