Commit b1147ef9 by golton_gao

update: 调整cordova的桥为yzj的桥

parent 794ad5d6
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>简历</title>
</head>
<body>
<div class="header">
</div>
<a class="header__button" id="back"></a>
<div class="container">
<div class="banner">
<a class="banner__img loading" id="mainPhoto">
<img>
</a>
<div id="name">正在加载</div>
</div>
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides.
PhotoSwipe keeps only 3 of them in the DOM to save memory.
Don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--save">保存</button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
</div>
<div class="toast" id="toast">
<div class="toast-content"></div>
</div>
<!-- 自定义弹窗 -->
<div class="my__modal">
<div class="modal__content">
<!-- 头部 -->
<div class="modal__header">
</div>
<!-- 内容 -->
<div class="modal__body">
</div>
<!-- 尾部 -->
<div class="model__footer">
<div class="model__line"></div>
<span class="modal__close">&times;</span>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>简历</title>
<script src="miniapp://common/js/qing/qing.js"></script>
</head>
<body>
<div class="header">
</div>
<a class="header__button" id="back"></a>
<div class="container">
<div class="banner">
<a class="banner__img loading" id="mainPhoto">
<img>
</a>
<div id="name">正在加载</div>
</div>
<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<!-- Background of PhotoSwipe.
It's a separate element as animating opacity is faster than rgba(). -->
<div class="pswp__bg"></div>
<!-- Slides wrapper with overflow:hidden. -->
<div class="pswp__scroll-wrap">
<!-- Container that holds slides.
PhotoSwipe keeps only 3 of them in the DOM to save memory.
Don't modify these 3 pswp__item elements, data is added later on. -->
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<!-- Controls are self-explanatory. Order can be changed. -->
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--save">保存</button>
<!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
<!-- element will get class pswp__preloader--active when preloader is running -->
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
</div>
<div class="toast" id="toast">
<div class="toast-content"></div>
</div>
<!-- 自定义弹窗 -->
<div class="my__modal">
<div class="modal__content">
<!-- 头部 -->
<div class="modal__header">
</div>
<!-- 内容 -->
<div class="modal__body">
</div>
<!-- 尾部 -->
<div class="model__footer">
<div class="model__line"></div>
<span class="modal__close">&times;</span>
</div>
</div>
</div>
<div class="tips__modal">
......@@ -129,8 +130,8 @@
</div>
</div>
</div>
</div>
<script defer src="cordova.js"></script>
</body>
</div>
<!-- <script defer src="cordova.js"></script> -->
</body>
</html>
This diff could not be displayed because it is too large.
......@@ -28,9 +28,14 @@ const app = {
*/
ready (fn, prod) {
if (!ready && prod) {
/* old-code
window.document.addEventListener('deviceready', () => {
doReady(fn)
}, false)
*/
qing.ready(function () {
doReady(fn)
})
} else {
doReady(fn)
}
......@@ -46,10 +51,10 @@ const app = {
return new Promise((resolve, reject) => {
if (window.cordova) {
cordova.exec(function (msg) {
resolve(msg)
}, function (msg) {
reject(msg)
}, module, method, params || [])
resolve(msg)
}, function (msg) {
reject(msg)
}, module, method, params || [])
} else {
reject('cordova is not exist.')
}
......
import './cordova.js'
import './request.js'
const events = {}
window.customEvt = {
addEventListener: function (name, fn) {
if (!events[name]) {
events[name] = []
}
const fns = events[name] || []
fns.push(fn)
},
removeEventListener: function (name, fn) {
const fns = events[name] || []
if (!fn) {
events[name] = []
return
}
for (let index = 0, len = fns.length; index < len; index++) {
const _fn = fns[index]
if (_fn === fn) {
fns.splice(index, 1)
break
}
}
},
triggerEvent: function (name) {
const fns = events[name] || []
for (const fn of fns) {
fn()
}
}
}
var customEvt = window.customEvt
var qing = window.qing
qing.ready(function () {
// 重写左侧返回按钮
qing.call('defback', {
success: function () {
customEvt.triggerEvent('backbutton')
}
})
// 绑定左侧按钮默认事件
customEvt.addEventListener('backbutton', () => {
if (history.length <= 1) {
//顶级页面,则关闭当前Web
qing.call('closeWebView')
} else {
history.back()
}
})
})
import axios from 'axios'
var originAdapter = axios.defaults.adapter
axios.defaults.adapter = function (config) {
if (!/^https?/.test(config.url)) {
return originAdapter(config)
}
return request(config)
}
function isObject(value) {
return value !== null && typeof value === 'object'
}
function isFormData(fd) {
return Object.prototype.toString.call(fd) === '[object FormData]'
}
function formData2obj(fd) {
var data = {}
for (var p of fd.entries()) {
data[p[0]] = p[1]
}
return data
}
function params2object(url) {
var params = {}
if (typeof url === 'object') {
return url
} else if (typeof url === 'string') {
url
.replace(/^.*\?|#.*$/g, '')
.split('&')
.forEach((n) => {
n = n.split('=')
if (n.length === 2) {
params[n[0]] = n[1]
}
})
}
return params
}
function request(opt) {
opt = opt || {}
if (!opt.url) {
return Promise.reject('interface url is required!')
}
// 默认get请求
opt.method = opt.method || 'get'
// 处理params
var urlParams = opt.params || {}
// 合并url和params字段的数据,如果params字段与url中有重名参数,以params中的为准
urlParams = Object.assign(params2object(opt.url), urlParams)
// 处理url
// url如果包含空格,会在iOS中报错
opt.url = opt.url.replace(/^\s+|\s+$/g, '')
// 将params拼接到url中
opt.url =
opt.url.split('?')[0] +
'?' +
Object.keys(urlParams)
.map((key) => {
var val = urlParams[key]
if (isObject(val)) {
val = JSON.stringify(val)
val = encodeURIComponent(val)
} else if (/[^\x00-\xff]/.test(val)) {
val = encodeURIComponent(val)
}
return key + '=' + val
})
.join('&')
// post非json即是form。
if (opt.method.toLowerCase() === 'post') {
var data = opt.data
if (isFormData(data)) {
opt.headers = Object.assign(opt.headers || {}, {
'Content-Type': 'application/x-www-form-urlencoded'
})
opt.data = formData2obj(data)
} else if (isObject(data)) {
opt.headers = Object.assign(opt.headers || {}, {
'Content-Type': 'application/json;charset=UTF-8'
})
}
}
// 处理header
opt.headers = opt.headers || {}
// headers字段值必须是字符串型
Object.keys(opt.headers).forEach(function (key) {
var val = opt.headers[key]
var type = typeof val
if (type === 'undefined') {
delete opt.headers[key]
} else if (type !== 'string') {
opt.headers[key] = val + ''
}
})
return new Promise(function (resolve, reject) {
qing.call('request', {
url: opt.url,
method: opt.method,
headers: opt.headers,
header: opt.headers,
data: opt.data || {},
dataType: opt.dataType,
success: function (resp) {
var response = {
data: resp.data,
status: resp.statusCode,
headers: resp.header,
config: opt
}
var validateStatus = response.config.validateStatus
// Note: status is not exposed by XDomainRequest
if (
!response.status ||
!validateStatus ||
validateStatus(response.status)
) {
resolve(response)
} else {
var error = new Error(
'Request failed with status code ' + response.status
)
error.config = response.config
error.response = response
reject(error)
}
},
error: function (e) {
var error = new Error(e)
error.config = opt
reject(error)
}
})
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment