UNPKG

h5-cli

Version:

hello

330 lines (281 loc) 10.3 kB
"use strict"; /** var page = PageModule.rendere({ init:function(){ }, onComplate:function(){ }, onSuccess:function(){ }, onError:function(){ }, renderTo:fucntion(){ } }); page.init(); */ define("component/PageModule", function (require, exports, module) { //lib.windvane \u5f3a\u4f9d\u8d56 var io = require("io"); var url = require("libs/url"); var util = require("libs/util"); var juicer = require("libs/juicer"); var cache = require("libs/cache"); var windvane = require("libs/windvane"); var vTemplate = require("libs/vTemplate"); var config = window.config; function PageModule() { //url\u4e0a\u7684\u5168\u90e8\u53c2\u6570 this.query = url.parse(window.location.href, true).query || {}; this.vTemplate = vTemplate; this.cache = cache; this.io = io; this.url = url; this.juicer = juicer; this.util = util; //\u5168\u5c40\u914d\u7f6e\u6587\u4ef6 this.config = config; //\u533b\u9662id \u53c2\u6570\u4e0a\u7684id --> confir.corpId // console.log( this.query ) this.corpId = this.query.corpId || this.config.corpId; try { //\u901a\u8fc7id\u8bbe\u7f6e\u533b\u9662\u540d\u79f0 this.corpName = config.cropMap[this.corpId].corpName; } catch (e) {} //\u5904\u7406 \u5047\u503c this.juicer.register("string", function (value) { if (value == null || value === undefined) { return ""; } return value; }); //\u6d4b\u8bd5\u5f00\u542f\u6bcf\u4e2a\u9875\u9762\u7684\u65f6\u95f4\u76d1\u542c\uff0c\u9700\u8981\u5220\u9664 this.initPageEvent(); // PageModule.checkVersion(); } PageModule.isCheckVerson = false; //\u68c0\u67e5\u5f53\u524dh5\u7248\u672c\uff0c\u5982\u679c\u5c0f\u4e8e\u7ebf\u4e0a\u914d\u7f6e\u7684\u7248\u672c\u53f7\u5219\u63d0\u793a\u7528\u6237\u8df3\u8f6c\u5230\u6700\u65b0\u7248\u672c PageModule.checkVersion = function () { if (!this.isCheckVerson) { this.isCheckVerson = true; var versionURL = "native-online-config.json"; if (config.isUAT) { versionURL = "native-uat-config.json"; } io.get("//s.yuantutech.com/tms/fb/proxy-jsonp.php", { config: versionURL }, function (data) { if (data && data.h5MinimumVersion) { var h5MinimumVersion = data.h5MinimumVersion.split("."); if (util.h5Version.lt(h5MinimumVersion[0], h5MinimumVersion[1], h5MinimumVersion[2])) { util.alert("\u4e3a\u4e86\u83b7\u5f97\u66f4\u597d\u7684\u4f53\u9a8c<br/>\u6211\u4eec\u5373\u5c06\u4e3a\u4f60\u8df3\u8f6c\u5230\u65b0\u7248\u672c"); setTimeout(function () { var href = window.location.pathname.replace(/\/yuantu\/h5\-cli\/[\d\.]+\//, "/") + window.location.search; if (config.isUAT) { window.location.href = "//s.yuantutech.com/tms/fb/weixin-nav-uat.php?url=" + encodeURIComponent(href); } else if (config.isDaily) { window.location.href = "//daily.yuantutech.com/tms/fb/weixin-nav-uat.php?url=" + encodeURIComponent(href); } else { //\u7ebf\u4e0a window.location.href = "//s.yuantutech.com/tms/fb/weixin-nav.php?url=" + encodeURIComponent(href); } }, 2000); } } var getPlatform = util.getPlatform(); //\u5224\u65ad\u5ba2\u6237\u7aef\u5c0f\u4e8e\u8bbe\u5b9a\u7684\u7248\u672c \u63d0\u793a\u5f3a\u5236\u66f4\u65b0 if (util.isInYuantuApp() && getPlatform == "ios" && data && data.iosMinimumVersion) { // if(true){ var version = data.iosMinimumVersion.split("."); if (util.version.lt(version[0], version[1], version[2])) { goDownload(); // $('<div class="version-low-mask"></div><div class="verson-low-tips"></div>').appendTo(document.body); } return; } //\u5224\u65ad\u5ba2\u6237\u7aef\u5c0f\u4e8e\u8bbe\u5b9a\u7684\u7248\u672c \u63d0\u793a\u5f3a\u5236\u66f4\u65b0 if (util.isInYuantuApp() && getPlatform == "android" && data && data.androidMinimumVersion) { var version = data.androidMinimumVersion.split("."); if (util.version.lt(version[0], version[1], version[2])) { goDownload(); // $('<div class="version-low-mask"></div><div class="verson-low-tips"></div>').appendTo(document.body); } return; } function goDownload() { util.dialog("\u5f53\u524dApp\u7248\u672c\u8f83\u4f4e\uff0c\u8bf7\u5148\u4e0b\u8f7d\u6700\u65b0\u7248\u672c", function (okay) { if (okay) { if (getPlatform == "ios") { window.location.href = "https://appsto.re/cn/jTqh8.i"; } else { window.location.href = "http://nocache-s.yuantutech.com/tms/fb/app-download.html" + (util.isInYuantuApp() ? "?target=_blank" : ""); } } }, { cancel: false, okText: "\u53bb\u4e0b\u8f7d" }); } }, function (err) {}); } }; // this.get(/url/, {id:}) PageModule.prototype = { //native\u4f1a\u901a\u8fc7jsbrige\u628a\u9875\u9762\u7684\u751f\u547d\u5468\u671f\u72b6\u6001\u4f20\u9012\u7ed9h5 initPageEvent: function initPageEvent() { var self = this; // console.log(windvane.eventListener) windvane.on(windvane.READY, function (result) { self.onPageReady(result); }); windvane.on(windvane.ACTIVEATION, function (result) { self.onActivation(result); }); windvane.on(windvane.PAUSE, function (result) { self.onPause(result); }); /** lib.windvane.fire({ ret:"SUCCESS", type:"event", name:"onready" }); lib.windvane.fire({ ret:"SUCCESS", type:"event", name:"onactivation" }); lib.windvane.fire({ ret:"SUCCESS", type:"event", name:"onpause" }); */ }, get: function get(url, param) { var self = this; console.log(url); // \u8ba9jsonp\u5f02\u6b65\uff0c\u628a\u65f6\u95f4\u8ba9\u6e21\u7ed9 \u9875\u9762\u6e32\u67d3\uff0c\u53ef\u4ee5\u8ba9\u9875\u9762\u66f4\u5feb\u7684onload setTimeout(function () { io.get(url, param, function (result) { self.onComplate(result); }, function (result) { if (result && result.success != undefined) { self.onComplate(result); } else { console.log('!!!!!'); self.onComplate({ success: false, msg: "\u7f51\u8def\u9519\u8bef\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5" }); } }); }); return this; }, getCache: function getCache(url, param) { var self = this; setTimeout(function () { io.getCache(url, param, function (result) { self.onComplate(result); }, function (result) { if (result && result.success != undefined) { self.onComplate(result); } else { console.log('!!!'); self.onComplate({ success: false, msg: "\u7f51\u8def\u9519\u8bef\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5" }); } }); }); return this; }, checkLogin: function checkLogin() { if (!this.util.isLogin()) { this.util.goLogin(true); // this.showLoginMask(); return false; } return true; }, showLoginMask: function showLoginMask() { var mask = $('<div class="ui-mask-tip-box"><div class="text">\u8bf7\u5148\u767b\u5f55<sub>\u70b9\u51fb\u4efb\u610f\u4f4d\u7f6e\u8df3\u8f6c\u5230\u767b\u5f55\u754c\u9762</sub></div></div>'); var self = this; mask.click(function () { if (!self.util.isLogin()) { self.util.goLogin(true); } else { window.location.reload(); } }); mask.appendTo(document.body); }, onComplate: function onComplate(result) { this.util.waitHide(); if (result.success) { this.onSuccess(result); } else { this.onError(result); } }, onSuccess: function onSuccess() { this.util.alert("\u64cd\u4f5c\u6210\u529f"); }, onError: function onError(result) { $('#J_Page').removeClass("wait"); this.errorHandle(result); }, //\u9875\u9762\u88c5\u5907\u5b8c\u6210 onPageReady: function onPageReady(event) { console.log(windvane.READY); }, //\u9875\u9762\u88ab\u6fc0\u6d3b onActivation: function onActivation(event) { console.log(windvane.ACTIVEATION); }, //\u9875\u9762\u88ab\u8f6c\u79fb\u5230\u540e\u53f0 onPause: function onPause(event) { console.log(windvane.PAUSE); }, errorHandle: function errorHandle(result) { if (result && result.resultCode == "202") { //\u672a\u767b\u5f55 // !this.util.isInYuantuApp() && this.showLoginMask(); // this.util.alert("\u8bf7\u5148\u767b\u5f55"); this.util.goLogin(); // alert(1) } else { this.util.alert(result ? result.msg : "\u5931\u8d25"); } }, renderTo: function renderTo(tmpl, data, id) { try { $(id).html(juicer(tmpl, data)); } catch (e) { console.log("\u6a21\u677f\u6e32\u67d3\u9519\u8bef", e); this.onError({ "success": "false", "code": "00" }); } }, //\u52a0\u8f7d\u5176\u4ed6\u6a21\u5757 use: function use(moduleNames) { setTimeout(function () { seajs.use(moduleNames); }, 1000); } }; PageModule.render = function (proto) { var module = $.extend(new PageModule(), proto); module.supperClass = PageModule.prototype; return module; }; PageModule.clearOtherNode = function () { var element = null; // console.log(document.body.lastElementChild) while ((element = document.body.lastElementChild) && element.id != "J_YuanTuLastScript" && element.innerHTML.indexOf("seajs.use") == -1) { console.log("\u6e05\u9664\u52ab\u6301 element \u751f\u6548"); document.body.removeChild(element); } }; // PageModule.clearOtherNode(); module.exports = PageModule; });