Commit 5c6601f5 authored by Nature's avatar Nature

template

parent 4baef966
...@@ -8,24 +8,38 @@ import vuexI18n from 'vuex-i18n' ...@@ -8,24 +8,38 @@ import vuexI18n from 'vuex-i18n'
import router from './router/index' import router from './router/index'
import flexible from './common/ydui.flexible' import flexible from './common/ydui.flexible'
import {componentInstall, appStyle, get, post, hlsUtil, hlsPopup, directives, filter} from 'hls-easy-ui' import {componentInstall, appStyle} from 'hls-easy-ui'
/** /**
* 组件 * 组件
*/ */
import { import {
ViewBox,
Tabbar,
TabbarItem,
XHeader,
Picker, Picker,
PopupHeader,
} from 'vux' } from 'vux'
import './scripts/prototype' import './scripts/prototype'
import './scripts/vuePlatform' import './scripts/vuePlatform'
/**
* 指令
*/
import directives from './scripts/directives'
import filter from './scripts/filter'
/**
* 弹框组件
*/
import hlsPopup from './scripts/hlsPopup'
/**
* http
*/
import { post, get } from './scripts/hlsHttp'
/** 全局函数hlsUtil**/
import hlsUtil from './scripts/hlsUtil'
Vue.use(componentInstall) Vue.use(componentInstall)
Vue.use(appStyle) Vue.use(appStyle)
...@@ -42,12 +56,6 @@ Vue.use(directives) ...@@ -42,12 +56,6 @@ Vue.use(directives)
Vue.use(filter) Vue.use(filter)
Vue.use(Vuex) Vue.use(Vuex)
// Vue.directive('transfer-dom', TransferDom);
Vue.component('x-header', XHeader)
Vue.component('view-box', ViewBox)
Vue.component('tabbar', Tabbar)
Vue.component('tabbar-item', TabbarItem)
Vue.component('PopupHeader', PopupHeader)
Vue.component('picker', Picker) Vue.component('picker', Picker)
/** i18n **/ /** i18n **/
......
This diff is collapsed.
export default (Vue) => {
Vue.filter('currency', function (val) {
if (!val) return '0.00'
var intPart = Number(val).toFixed(0) // 获取整数部分
var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') // 将整数部分逢三一断
var floatPart = '.00' // 预定义小数部分
var value2Array = (val + '').split('.')
// =2表示数据有小数位
if (value2Array.length === 2) {
floatPart = value2Array[1].toString() // 拿到小数部分
if (floatPart.length === 1) { // 补0,实际上用不着
return intPartFormat + '.' + floatPart + '0'
} else {
return intPartFormat + '.' + floatPart
}
} else {
return intPartFormat + floatPart
}
})
Vue.filter('datetime', timestamp => {
function format (number) {
return number.toString().padStart(2, '0')
}
const date = new Date(Number.parseInt(timestamp, 10))
const YYYY = date.getFullYear()
const MM = date.getMonth() + 1
const DD = date.getDate()
const hh = date.getHours()
const mm = date.getMinutes()
const ss = date.getSeconds()
return `${YYYY}-${format(MM)}-${format(DD)} ${format(hh)}:${format(mm)}:${format(ss)}`
})
}
// 引入axios
import axios from 'axios'
import hlsPopup from './hlsPopup'
let promiseArr = {}
let cancel = {}
const CancelToken = axios.CancelToken
// 请求拦截器
axios.interceptors.request.use(config => {
// 发起请求时,取消掉当前正在进行的相同请求
config.cancelToken = new CancelToken(c => {
cancel = c
})
if (promiseArr[config.url]) {
promiseArr[config.url]('操作取消')
promiseArr[config.url] = cancel
} else {
promiseArr[config.url] = cancel
}
return config
}, error => {
return Promise.reject(error)
})
// 响应拦截器即异常处理
axios.interceptors.response.use(response => {
if ($config.debug) {
let postName = 'post'
console.log(postName + ' success')
console.log(postName + ' response ' + JSON.stringify(response.data, '', 2))
console.log(postName + ' End!')
}
if (response.data.result === 'E' || response.data.code === 'E') {
hlsPopup.hideLoading()
const err = {}
err.message = response.data.message
hlsPopup.showError(err.message)
return Promise.resolve(err)
} else {
return response.data
}
}, err => {
if (err && err.response) {
switch (err.response.status) {
case 400:
err.message = '错误请求'
break
case 401:
err.message = '登录已失效,请重新登录'
break
case 403:
err.message = '拒绝访问'
break
case 404:
err.message = '请求错误,未找到该资源'
break
case 405:
err.message = '不支持的请求类型'
break
case 408:
err.message = '请求超时'
break
case 500:
err.message = '服务器端出错'
break
case 501:
err.message = '网络未实现'
break
case 502:
err.message = '网络错误'
break
case 503:
err.message = '服务不可用'
break
case 504:
err.message = '网络超时'
break
case 505:
err.message = 'http版本不支持该请求'
break
default:
err.message = `连接错误${err.response.status}`
}
} else {
err.message = '连接到服务器失败'
}
if (err.response && err.response.status === 401) {
hlsPopup.hideLoading()
hlsPopup.showPopup({
title: '登录失效,重新登录',
onConfirm: () => {
// router.push({name: 'Login'})
if (vum.Platform.isIOS()) {
cordova.exec(null, null, 'BridgePlugin', 'closeWebView', [])
} else if (vum.Platform.isIOS()) {
var dict = {
'className': 'WebBridge',
'function': 'close',
'successCallBack': 'sCallBack',
'failureCallBack': 'eCallBack',
}
HandBridge.postMessage(JSON.stringify(dict))
}
},
})
} else {
hlsPopup.hideLoading()
hlsPopup.showError(err.message)
}
return Promise.resolve(err)
})
axios.defaults.baseURL = ''
axios.defaults.timeout = 10000
// get请求
export function get (url) {
let param = {}
let headers = {}
if (window.localStorage.access_token) {
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + window.localStorage.access_token,
}
} else {
headers = {
'Content-Type': 'application/json',
}
}
if ($config.debug) {
let postName = 'GET'
console.log(postName + ' Start!')
console.log(postName + ' url ' + url)
}
return new Promise((resolve, reject) => {
axios({
method: 'get',
url,
headers: headers,
params: param,
}).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
})
}
// post请求
export function post (url, param) {
param.user_id = window.localStorage.user_id
param.access_token = window.localStorage.access_token
let headers = {}
if (window.localStorage.access_token) {
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + window.localStorage.access_token,
}
} else {
headers = {
'Content-Type': 'application/json',
}
}
if ($config.debug) {
let postName = 'POST'
console.log(postName + ' Start!')
console.log(postName + ' url ' + url)
console.log(postName + ' parameter ' + JSON.stringify(param, '', 2))
}
return new Promise((resolve, reject) => {
axios({
method: 'post',
headers: headers,
url,
data: param,
}).then(res => {
resolve(res)
}).catch(err => {
reject(err)
})
})
}
This diff is collapsed.
This diff is collapsed.
...@@ -3814,17 +3814,14 @@ he@1.2.x, he@^1.1.0: ...@@ -3814,17 +3814,14 @@ he@1.2.x, he@^1.1.0:
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
"hls-easy-ui@https://hel.hand-china.com/easyUI/hls-easy-ui.git": "hls-easy-ui@https://hel.hand-china.com/easyUI/hls-easy-ui.git":
version "0.0.2" version "0.0.3"
resolved "https://hel.hand-china.com/easyUI/hls-easy-ui.git#0492206ed12c4bb6f0bb8edc19f7f5da77a0c858" resolved "https://hel.hand-china.com/easyUI/hls-easy-ui.git#3e65dbb22b596b6d517dbfaba932e9c1cc8bad47"
dependencies: dependencies:
autosize "^3.0.20" autosize "^3.0.20"
better-scroll "^1.10.3" better-scroll "^1.10.3"
crypto-js "^3.1.9-1"
fastclick "https://hel.hand-china.com/easyUI/fastclick.git" fastclick "https://hel.hand-china.com/easyUI/fastclick.git"
vue "^2.5.2" vue "^2.5.2"
vue-router "^3.0.1" vue-router "^3.0.1"
vuex "^2.1.1"
vuex-i18n "^1.3.1"
vux "^2.9.2" vux "^2.9.2"
hmac-drbg@^1.0.0: hmac-drbg@^1.0.0:
......
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 to comment