Commit 32e39373 by golton_gao

update: 替换js桥为yzj的桥

parent ff58a1eb
...@@ -24,7 +24,8 @@ export default class CordovaApi extends NativeApi { ...@@ -24,7 +24,8 @@ export default class CordovaApi extends NativeApi {
conf = conf || {} conf = conf || {}
conf.platform = 'cordova' conf.platform = 'cordova'
super(conf) super(conf)
var self = this
/*
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
var self = this var self = this
if (!window.document.getElementById('cordovaJS')) { if (!window.document.getElementById('cordovaJS')) {
...@@ -45,6 +46,10 @@ export default class CordovaApi extends NativeApi { ...@@ -45,6 +46,10 @@ export default class CordovaApi extends NativeApi {
window.document.body.appendChild(script) window.document.body.appendChild(script)
} }
} }
*/
window.qing.ready(() => {
self.doReady(self)
})
} }
set methods (methods) { set methods (methods) {
......
// 弹窗方法api // 弹窗方法api
const Alert = (title, func) => { const Alert = (title, func) => {
const titl = title const titl = title
/*
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'provt') { if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'provt') {
navigator.notification.alert(titl, func, '', '确定'); navigator.notification.alert(titl, func, '', '确定');
} else { } else {
window.alert(titl) window.alert(titl)
func() func()
} }
*/
window.alert(titl)
func()
} }
const Confirm = (title, func) => { const Confirm = (title, func) => {
const tit = title const tit = title
/*
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'provt') { if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'provt') {
navigator.notification.confirm(tit, function (buttonIndex) { navigator.notification.confirm(tit, function (buttonIndex) {
if (buttonIndex == 1) { if (buttonIndex == 1) {
...@@ -27,6 +32,13 @@ const Confirm = (title, func) => { ...@@ -27,6 +32,13 @@ const Confirm = (title, func) => {
func(false) func(false)
} }
} }
*/
let res = window.confirm(tit)
if (res) {
func(true)
} else {
func(false)
}
} }
export default { export default {
......
// The Vue build version to load with the `import` command // The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import './polyfill/index'
import Vue from 'vue' import Vue from 'vue'
import App from '@/App' import App from '@/App'
import router from '@/router' import router from '@/router'
...@@ -33,12 +34,13 @@ Vue.config.productionTip = false ...@@ -33,12 +34,13 @@ Vue.config.productionTip = false
Vue.component('title-bar', TitleBar) // 全局注册标题栏 Vue.component('title-bar', TitleBar) // 全局注册标题栏
Vue.component('page', BasePage) Vue.component('page', BasePage)
Vue.prototype.$dialog = Dialog // 全局的对话框 Vue.prototype.$dialog = Dialog // 全局的对话框
let VMT let VMT
/* eslint-disable no-new */ /* eslint-disable no-new */
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
/*
document.addEventListener('deviceready', function () { document.addEventListener('deviceready', function () {
VMT = new Vue({ VMT = new Vue({
el: '#app', el: '#app',
...@@ -47,6 +49,15 @@ if (process.env.NODE_ENV === 'production') { ...@@ -47,6 +49,15 @@ if (process.env.NODE_ENV === 'production') {
render: h => h(App) render: h => h(App)
}) })
}) })
*/
window.qing.ready(function () {
VMT = new Vue({
el: '#app',
router,
store,
render: (h) => h(App)
})
})
} else { } else {
VMT = new Vue({ VMT = new Vue({
el: '#app', el: '#app',
......
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) {
window.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