Skip to content

Commit

Permalink
updata to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tower1229 committed Apr 27, 2018
1 parent 06f4747 commit 96e7fa3
Show file tree
Hide file tree
Showing 138 changed files with 713 additions and 3,756 deletions.
20 changes: 1 addition & 19 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,7 @@ <h4>代码组织</h4>
<p>SDK包含核心库、插件、公用代码、UI;View包含所有APP页面,APP页面体现为一个至少包含<code>temp.html</code><code>style.css</code><code>script.js</code>三个文件的文件夹,页面文件夹在<code>view/</code>中最多嵌套两层,即<code>/view/[...]/page/</code></p>
<h4>开发模式</h4>
<p>HybridStart 约定APP的生命周期为 <code>`root -> index(exit) <=> page <=> page ...`</code>,启动页即<code>root</code>通常没有任何可见内容,只执行APP的状态检测、插件调用、监听、数据初始化等操作,完成后直接跳转到用户可见的首页(<code>index</code>),首页与展示页之间任意跳转返回,但要在首页拦截返回键,使(安卓)APP无法返回启动页,而是退出APP,整个生命周期内启动页都在后台运行。</p>
<h4>交互约定</h4>
<p>约定前后端交互数据基本格式如下:</p>
<pre>
<code>
{
"status": "Y", //请求的状态 "Y"/"N",也可以根据情况扩展其他
"data": [{...}], //请求的数据 数组或对象
"msg": "", //【可选】服务端提示信息
"count": [number] //【可选】当获取列表数据时,需附加count数据指明列表总数,用于前段判断是否还有更多
}
</code>
</pre>


<h3 id="getStart">快速开始</h3>
<ol>
<li>在APICloud平台创建新项目,添加以下模块:UIPullRefreshFlash、ajpush、bMap、mam</li>
Expand Down Expand Up @@ -1414,12 +1402,6 @@ <h5>配置</h5>
<p>请求数据格式,默认<code>"json"</code></p>
</td>
</tr>
<tr>
<td>checkData</td>
<td>
<p>是否检查约定数据格式,仅当dataType为"json"时有效,默认<code>true</code></p>
</td>
</tr>
<tr>
<td>timeout</td>
<td>
Expand Down
34 changes: 15 additions & 19 deletions sdk/core.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
app JS SDK
Version:2.3.1
update: app.loading() bug fix
date:2018-01-30
Version:2.4.0
update: 移除app.ajax错误检查
date:2018-04-27
*
/*! Sea.js 2.2.1 | seajs.org/LICENSE.md */
Expand Down Expand Up @@ -1159,7 +1159,6 @@ var gh=((((ga*ga)>>>17)+ga*gb)>>>15)+gb*gb;var gl=(((gx&4294901760)*gx)|0)+(((gx
tag: 'ajax-tag' + (++ajaxTag),
method: appcfg.ajax.type,
dataType: 'json',
checkData: true,
timeout: appcfg.set.outime / 1000,
snapshoot: null //添加为快照
}, config);
Expand All @@ -1180,23 +1179,19 @@ var gh=((((ga*ga)>>>17)+ga*gb)>>>15)+gb*gb;var gl=(((gx&4294901760)*gx)|0)+(((gx
}
var handleRes = function(res, fromSnap) {
if (res) {
if (opt.dataType === 'json' && opt.checkData && res['status'] === void(0)) {
handleError(null, {
code: '数据格式错误!',
statusCode: 200
});
} else {
if (res['data'] && res.data.split) {
try {
res.data = JSON.parse(res.data);
} catch (e) {}
};
//存储快照
if(opt.snapshoot && !fromSnap){
app.storage.val(urlkey, res);
//json格式异常处理
if(opt.dataType==="json" && res.data && res.data.split){
try{
res.data = JSON.parse(res.data);
}catch(e){
console.log(e.msg)
}
tempSucc(res);
}
//存储快照
if(opt.snapshoot && !fromSnap){
app.storage.val(urlkey, res);
}
tempSucc(res);
}
}
delete opt.success;
Expand Down Expand Up @@ -1279,6 +1274,7 @@ var gh=((((ga*ga)>>>17)+ga*gb)>>>15)+gb*gb;var gl=(((gx&4294901760)*gx)|0)+(((gx
values: opt.data
};
}
//console.log(JSON.stringify(opt))
api.ajax(opt, function(res, err) {
handleRes(res);
handleError(res, err);
Expand Down
53 changes: 53 additions & 0 deletions sdk/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var scriptName = "./" + (document.currentScript.dataset.script || "script");
var headNode = document.getElementsByTagName('head')[0];
var confNode = document.createElement('script');
var coreNode = document.createElement('script');
var selfPath = window.location.href;
var widgetPath = "widget://";
var pathMatch = selfPath.match(/\/view(.+)$/);
if (pathMatch[1]) {
selfPath = pathMatch[1];
var index = -1;
var pathDeep = 0;
do {
index = selfPath.indexOf("/", index + 1);
if (index != -1) {
pathDeep++;
}
} while (index != -1);
if (pathDeep) {
widgetPath = "";
for (var deepStart = 0; deepStart < pathDeep; deepStart++) {
widgetPath += "../";
}
}
}

confNode.type = "text/javascript";
confNode.src = widgetPath + "config.js";
coreNode.type = "text/javascript";

if (coreNode.addEventListener) {
coreNode.addEventListener("load", scriptOnload, false);
} else if (coreNode.readyState) {
coreNode.onreadystatechange = function() {
if (coreNode.readyState == "loaded" || coreNode.readyState == "complete") {
coreNode.onreadystatechange = null;
scriptOnload();
}
};
} else {
coreNode.onload = scriptOnload;
}
coreNode.src = widgetPath + "sdk/core.js";
coreNode.onerror = function(e) {
console.log(JSON.stringify(e));
};
apiready = function() {
headNode.appendChild(confNode);
headNode.appendChild(coreNode);
};

function scriptOnload() {
seajs.use(scriptName);
}
47 changes: 26 additions & 21 deletions sdk/modules/validform/validform.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* name: validform.js
* version: v2.5.3
* update: 修复弹窗颜色bug
* data: 2017-06-25
* version: v2.5.11
* update: ajaxPost默认true
* data: 2018-04-26
*/
define('validform',function(require, exports, module) {
define('validform', function(require, exports, module) {
"use strict";

seajs.importStyle('.Validform_right{color:#71b83d}.Validform_wrong{color:red;white-space:nowrap}.Validform_loading{padding-left:20px}.Validform_error{background-color:#ffe7e7}.passwordStrength{display:block;height:18px;line-height:16px;clear:both;overflow:hidden;margin-bottom:5px}.passwordStrength b{font-weight:normal}.passwordStrength b,.passwordStrength span{display:inline-block;vertical-align:middle;line-height:16px;height:16px}.passwordStrength span{width:63px;text-align:center;background-color:#d0d0d0;border-right:1px solid #fff}.passwordStrength .last{border-right:0;width:61px}.passwordStrength .bgStrength{color:#fff;background-color:#71b83d}'
Expand Down Expand Up @@ -46,7 +46,7 @@ define('validform',function(require, exports, module) {
tipSweep: true,
showAllError: false,
postonce: false,
ajaxPost: false,
ajaxPost: true,
checkTime: 100 //验证延时
};
var Validform = function(forms, settings, inited) {
Expand Down Expand Up @@ -653,14 +653,16 @@ define('validform',function(require, exports, module) {
curform.find(".Validform_error:first").focus();
}
if (flag) {
var beforeSubmit;
try{
beforeSubmit = !settings.beforeSubmit || ($.isFunction(settings.beforeSubmit) && settings.beforeSubmit(curform));
}catch(e){
alert(e.message);
}
if (!beforeSubmit) {
return false;
if(!flg){
var beforeSubmit;
try{
beforeSubmit = !settings.beforeSubmit || ($.isFunction(settings.beforeSubmit) && settings.beforeSubmit(curform));
}catch(e){
alert(e.message);
}
if (!beforeSubmit) {
return false;
}
}
curform[0].validform_status = "posting";

Expand Down Expand Up @@ -700,16 +702,15 @@ define('validform',function(require, exports, module) {
};
}
var _sendData = {},
_cloneForm,
_formData;
_formData = curform.serializeArray();
if(settings.allable){
_cloneForm = curform.clone();
_cloneForm.find(':disabled').each(function(i,e){
curform.find(':disabled').each(function(i,e){
$(e).prop('disabled',false);
_formData.push({
name: $(e).attr('name'),
value: $(e).val()
});
});
_formData = _cloneForm.serializeArray();
}else{
_formData = curform.serializeArray();
}
$.each(_formData, function(i,e){
if(_sendData[e.name] === void 0){
Expand All @@ -728,8 +729,12 @@ define('validform',function(require, exports, module) {
dynamicAjaxData=settings.ajaxData||{};
}
$.extend(_sendData, dynamicAjaxData);

var localconfig = {
type: "POST",
async: true,
data: _sendData, //$.extend(_sendData, settings.ajaxData || {}),
dataType: settings.dataType || 'json',
success: function(data) {
if (data) {
curform[0].validform_status = "posted";
Expand All @@ -745,7 +750,7 @@ define('validform',function(require, exports, module) {
curform[0].validform_ajax = null;
},
error: function(err) {
console.warn('validform提交失败!');
console.warn(err.msg);
curform[0].validform_status = "normal";
curform[0].validform_ajax = null;
}
Expand Down
Loading

0 comments on commit 96e7fa3

Please sign in to comment.