Commit 9da24186 by golton_gao

update: 更新代码逻辑

parent 48d422d6
...@@ -28,7 +28,8 @@ var webpackConfig = merge(baseWebpackConfig, { ...@@ -28,7 +28,8 @@ var webpackConfig = merge(baseWebpackConfig, {
plugins: [ plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html // http://vuejs.github.io/vue-loader/en/workflow/production.html
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'process.env': env 'process.env': env,
'process.env.PACK_ENV': JSON.stringify(process.env.PACK_ENV)
}), }),
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
compress: { compress: {
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
"dev": "node build/dev-server.js", "dev": "node build/dev-server.js",
"build": "node build/build.js", "build": "node build/build.js",
"lint": "eslint --ext .js,.vue src", "lint": "eslint --ext .js,.vue src",
"build:prod": "node build/vt-build.js", "build:test": "cross-env PACK_ENV=test node build/vt-build.js",
"build:zip": "node build/vt-build.js" "build:prod": "cross-env PACK_ENV=product node build/vt-build.js"
}, },
"dependencies": { "dependencies": {
"axios": "^0.16.2", "axios": "^0.16.2",
......
...@@ -13,7 +13,8 @@ import Dialog from '@/base/plugins/dialog' ...@@ -13,7 +13,8 @@ import Dialog from '@/base/plugins/dialog'
// 全局axios默认配置 // 全局axios默认配置
// axios.defaults.baseURL = APIPath.HOST // 正式环境 // axios.defaults.baseURL = APIPath.HOST // 正式环境
axios.defaults.baseURL = APIPath.TESTHOST // 测试环境 // axios.defaults.baseURL = APIPath.TESTHOST // 测试环境
axios.defaults.baseURL = process.env.PACK_ENV === 'product' ? APIPath.HOST : APIPath.TESTHOST
Vue.prototype.$axios = axios Vue.prototype.$axios = axios
// 获取屏幕宽高 // 获取屏幕宽高
...@@ -28,7 +29,7 @@ Vue.prototype.getViewportSize = function () { ...@@ -28,7 +29,7 @@ Vue.prototype.getViewportSize = function () {
import nativeApi from './base/NativeApi/cordova' import nativeApi from './base/NativeApi/cordova'
Vue.use(nativeApi, Object.assign({ debug: true, maxRetryTimes: 10, retrySleepTime: 100 })) Vue.use(nativeApi, Object.assign({ debug: true, maxRetryTimes: 10, retrySleepTime: 100 }))
// 判断是否V+模块 // 判断是否V+模块
Vue.prototype.$vPlusModule = process.env.NODE_ENV === 'provt' Vue.prototype.$vPlusModule = window.qing.isSupportNativeJsBridge
Vue.config.productionTip = false Vue.config.productionTip = false
...@@ -36,35 +37,14 @@ Vue.component('title-bar', TitleBar) // 全局注册标题栏 ...@@ -36,35 +37,14 @@ Vue.component('title-bar', TitleBar) // 全局注册标题栏
Vue.component('page', BasePage) Vue.component('page', BasePage)
Vue.prototype.$dialog = Dialog // 全局的对话框 Vue.prototype.$dialog = Dialog // 全局的对话框
let VMT const vm = new Vue({
router,
store,
render: (h) => h(App)
})
/* eslint-disable no-new */ window.qing.ready(function () {
if (process.env.NODE_ENV === 'production') { vm.$mount('#app')
/* })
document.addEventListener('deviceready', function () {
VMT = new Vue({
el: '#app',
router,
store,
render: h => h(App)
})
})
*/
window.qing.ready(function () {
VMT = new Vue({
el: '#app',
router,
store,
render: (h) => h(App)
})
})
} else {
VMT = new Vue({
el: '#app',
router,
store,
render: h => h(App)
})
}
export default VMT export default vm
...@@ -12,6 +12,10 @@ function isObject (value) { ...@@ -12,6 +12,10 @@ function isObject (value) {
return value !== null && typeof value === 'object' return value !== null && typeof value === 'object'
} }
function isString (fd) {
return Object.prototype.toString.call(fd) === '[object String]'
}
function isFormData (fd) { function isFormData (fd) {
return Object.prototype.toString.call(fd) === '[object FormData]' return Object.prototype.toString.call(fd) === '[object FormData]'
} }
...@@ -35,7 +39,7 @@ function params2object (url) { ...@@ -35,7 +39,7 @@ function params2object (url) {
.forEach((n) => { .forEach((n) => {
n = n.split('=') n = n.split('=')
if (n.length === 2) { if (n.length === 2) {
params[n[0]] = n[1] params[n[0]] = decodeURIComponent(n[1])
} }
}) })
} }
...@@ -43,6 +47,7 @@ function params2object (url) { ...@@ -43,6 +47,7 @@ function params2object (url) {
} }
function request (opt) { function request (opt) {
let serializer = opt.serializer || 'form'
opt = opt || {} opt = opt || {}
if (!opt.url) { if (!opt.url) {
return Promise.reject('interface url is required!') return Promise.reject('interface url is required!')
...@@ -78,35 +83,52 @@ function request (opt) { ...@@ -78,35 +83,52 @@ function request (opt) {
// post非json即是form。 // post非json即是form。
if (opt.method.toLowerCase() === 'post') { if (opt.method.toLowerCase() === 'post') {
var data = opt.data var data = opt.data
if (isFormData(data)) { const headers = opt.headers
opt.headers = Object.assign(opt.headers || {}, { const contentType = headers['content-type'] || headers['Content-Type'] || headers['CONTENT-TYPE'] || ''
'Content-Type': 'application/x-www-form-urlencoded' if (contentType.indexOf('application/json') !== -1) {
}) serializer = 'json'
}
if ((serializer === 'form') && isFormData(data)) {
opt.data = formData2obj(data) opt.data = formData2obj(data)
} else if (isObject(data)) { } else if (isString(data)) {
opt.headers = Object.assign(opt.headers || {}, { if (serializer === 'json') {
'Content-Type': 'application/json;charset=UTF-8' try {
}) opt.data = JSON.parse(data)
} catch (error) {
opt.data = {}
}
} else {
opt.data = params2object(data)
}
} }
} }
// 处理header // 处理header
opt.headers = opt.headers || {} opt.headers = opt.headers || {}
const headers = {}
// headers字段值必须是字符串型 // headers字段值必须是字符串型
Object.keys(opt.headers).forEach(function (key) { Object.keys(opt.headers).forEach(function (key) {
var val = opt.headers[key] var val = opt.headers[key]
var type = typeof val if (val) {
if (type === 'undefined') { var type = typeof val
delete opt.headers[key] if (type !== 'string') {
} else if (type !== 'string') { val = val + ''
opt.headers[key] = val + '' }
// 因content-type可能存在大小写不规范,这里先过滤掉,后面根据serializer统一添加
var _key = key.toLowerCase()
if (_key !== 'content-type') {
headers[_key] = val
}
} }
}) })
// 根据serializer统一添加content-type
headers['content-type'] = serializer === 'json' ? 'application/json' : 'application/x-www-form-urlencoded'
opt.headers = headers
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
window.qing.call('request', { window.qing.call('request', {
url: opt.url, url: opt.url,
method: opt.method, method: opt.method.toUpperCase(),
headers: opt.headers, headers: opt.headers,
header: opt.headers, header: opt.headers,
data: opt.data || {}, data: opt.data || {},
......
...@@ -9,10 +9,11 @@ import axios from 'axios'; ...@@ -9,10 +9,11 @@ import axios from 'axios';
// 全局axios默认配置 // 全局axios默认配置
// axios.defaults.baseURL = APIPath.HOST // axios.defaults.baseURL = APIPath.HOST
// axios.defaults.baseURL = APIPath.TESTHOST // axios.defaults.baseURL = APIPath.TESTHOST
// 'Authorization': 'Basic c21zc2VydmljZXVzZXI6ZmRjVXNlcjY1NCNAIQ=='// 正式环境 账号 smsserviceuser 密码 fdcUser654#@!
// 'Authorization': 'Basic c21zc2VydmljZXVzZXI6amZmY0AxMjM=' // 测试环境 账号 wuqk@cndrealty.com 密码 123456
axios.defaults.headers = { axios.defaults.headers = {
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
// 'Authorization': 'Basic c21zc2VydmljZXVzZXI6ZmRjVXNlcjY1NCNAIQ=='// 正式环境 账号 smsserviceuser 密码 fdcUser654#@! // todo 获取登录后的账号密码进行封装 'Basic c21zc2VydmljZXVzZXI6ZmRjVXNlcjY1NCNAIQ==' 'Authorization': process.env.PACK_ENV === 'product' ? 'Basic c21zc2VydmljZXVzZXI6ZmRjVXNlcjY1NCNAIQ==' : 'Basic c21zc2VydmljZXVzZXI6amZmY0AxMjM='
'Authorization': 'Basic c21zc2VydmljZXVzZXI6amZmY0AxMjM=' // 测试环境 账号 wuqk@cndrealty.com 密码 123456
} }
axios.defaults.timeout = 60 * 1000 axios.defaults.timeout = 60 * 1000
// 传json格式参数,不需要 // 传json格式参数,不需要
......
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