Commit 7871fa46 authored by 刘文虎's avatar 刘文虎

Initial commit

parents
Pipeline #2670 canceled with stages
.DS_Store
node_modules/
unpackage/
npm-debug.log*
**/*.log
tests/**/coverage/
tests/e2e/reports
selenium-debug.log
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.local
package-lock.json
yarn.lock
{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
"version": "0.0",
"configurations": [{
"default" :
{
"launchtype" : "local"
},
"mp-weixin" :
{
"launchtype" : "local"
},
"type" : "uniCloud"
}
]
}
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import 'uview-ui/index.scss';
</style>
<style>
@import '@/static/styles/base.css';
</style>
import request from "@/utils/request.js"
export function addBind(data) {
return request({
url: `/iov/business/deviceInfo/bind`,
method: 'POST',
data
})
}
\ No newline at end of file
<template>
<u-tabbar :list="tabbar" :mid-button="true"></u-tabbar>
</template>
<script>
import {tabbar} from "@/utils/settings.js"
export default {
name:"lw-tabbar",
data() {
return {
tabbar
};
}
}
</script>
<style lang="scss" scoped>
</style>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<title></title>
<!--preload-links-->
<!--app-context-->
</head>
<body>
<div id="app"><!--app-html--></div>
<script type="module" src="/main.js"></script>
</body>
</html>
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
import {router,RouterMount} from './router' //路径换成自己的
Vue.use(router)
import uView from "uview-ui";
Vue.use(uView);
import store from './store'
App.mpType = 'app'
const app = new Vue({
...App,
store,
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif
\ No newline at end of file
{
"name" : "account-book",
"appid" : "__UNI__C731E8B",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* 模块配置 */
"modules" : {},
/* 应用发布信息 */
"distribute" : {
/* android打包配置 */
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
]
},
/* ios打包配置 */
"ios" : {},
/* SDK配置 */
"sdkConfigs" : {}
}
},
/* 快应用特有相关 */
"quickapp" : {},
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
},
"usingComponents" : true
},
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics" : {
"enable" : false
},
"vueVersion" : "2"
}
{
"name": "digital-key",
"version": "1.0.0",
"description": "",
"main": "main.js",
"dependencies": {
"uni-read-pages": "^1.0.5",
"uni-simple-router": "^2.0.6",
"uview-ui": "^1.8.4"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.banshouhui.com/liuwenhu/account-book.git"
},
"author": "",
"license": "ISC"
}
{
"easycom": {
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
},
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app"
}
}, {
"path": "pages/index/schedule",
"style": {
"navigationBarTitleText": "行程",
"enablePullDownRefresh": false
}
}, {
"path": "pages/index/account",
"style": {
"navigationBarTitleText": "记账",
"enablePullDownRefresh": false
}
}, {
"path": "pages/index/bill",
"style": {
"navigationBarTitleText": "账单",
"enablePullDownRefresh": false
}
}, {
"path": "pages/index/mine",
"style": {
"navigationBarTitleText": "我的",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"tabBar": {
"color": "#909399",
"selectedColor": "#303133",
"backgroundColor": "#FFFFFF",
"borderStyle": "black",
"list": [{
"pagePath": "pages/index/index",
"iconPath": "/static/image/index/service_unclick@2x.png",
"selectedIconPath": "/static/image/index/service_click@2x.png",
"text": "首页"
}, {
"pagePath": "pages/index/schedule",
"iconPath": "/static/image/index/control_car_gray@2x.png",
"selectedIconPath": "/static/image/index/control_car_click@2x.png",
"text": "行程"
}, {
"pagePath": "pages/index/account",
"iconPath": "/static/image/index/tianj@2x.png",
"selectedIconPath": "/static/image/index/tianj@2x.png",
"text": ""
}, {
"pagePath": "pages/index/bill",
"iconPath": "/static/image/index/service_unclick@2x.png",
"selectedIconPath": "/static/image/index/service_click@2x.png",
"text": "账单"
}, {
"pagePath": "pages/index/mine",
"iconPath": "/static/image/index/personal_center_unclick@2x.png",
"selectedIconPath": "/static/image/index/personal_center_click@2x.png",
"text": "我的"
}]
}
}
<template>
<view>
<!-- <lw-tabbar></lw-tabbar> -->
<u-tabbar :list="tabbar" :mid-button="true"></u-tabbar>
</view>
</template>
<script>
import LwTabbar from "@/components/lw-tabbar/lw-tabbar.vue"
import {tabbar} from "@/utils/settings.js"
export default {
components:{
LwTabbar
},
data() {
return {
tabbar
};
}
}
</script>
<style lang="scss" scoped>
</style>
<template>
<view>
<!-- <lw-tabbar></lw-tabbar> -->
<u-tabbar :list="tabbar" :mid-button="true"></u-tabbar>
</view>
</template>
<script>
import LwTabbar from "@/components/lw-tabbar/lw-tabbar.vue"
import {tabbar} from "@/utils/settings.js"
export default {
components:{
LwTabbar
},
data() {
return {
tabbar
};
}
}
</script>
<style lang="scss" scoped>
</style>
<template>
<view>
<lw-tabbar></lw-tabbar>
<!-- <u-tabbar :list="tabbar" :mid-button="true"></u-tabbar> -->
</view>
</template>
<script>
import LwTabbar from "@/components/lw-tabbar/lw-tabbar.vue"
import {tabbar} from "@/utils/settings.js"
export default {
components:{
LwTabbar
},
data() {
return {
tabbar
};
}
}
</script>
<style lang="scss" scoped>
</style>
<template>
<view>
<!-- <lw-tabbar></lw-tabbar> -->
<u-tabbar :list="tabbar" :mid-button="true"></u-tabbar>
</view>
</template>
<script>
import LwTabbar from "@/components/lw-tabbar/lw-tabbar.vue"
import {tabbar} from "@/utils/settings.js"
export default {
components:{
LwTabbar
},
data() {
return {
tabbar
};
}
}
</script>
<style lang="scss" scoped>
</style>
<template>
<view>
<!-- <lw-tabbar></lw-tabbar> -->
<u-tabbar :list="tabbar" :mid-button="true"></u-tabbar>
</view>
</template>
<script>
import LwTabbar from "@/components/lw-tabbar/lw-tabbar.vue"
import {tabbar} from "@/utils/settings.js"
export default {
components:{
LwTabbar
},
data() {
return {
tabbar
};
}
}
</script>
<style lang="scss" scoped>
</style>
import {
checkToken,
getUserinfo,
checkCodeTimetamp,
showToast
} from "@/utils/common.js"
import store from "@/store/index.js"
import {
getCode
} from "@/utils/auth.js"
import {
RouterMount,
createRouter
} from 'uni-simple-router';
let first = null;
const router = createRouter({
platform: process.env.VUE_APP_PLATFORM,
APP: {
animation: {
animationType: 'slide-in-top',
animationDuration: 300
}
},
routerBeforeEach: (to, from, next) => {
console.log('+++++routerBeforeEach++++')
console.log(to)
next()
},
routerAfterEach: (to, from) => {
console.log('--------routerAfterEach----')
},
routerErrorEach: ({
type,
msg
}) => {
console.log({
type,
msg
})
// #ifdef APP-PLUS
// if(type===3){
// router.$lockStatus=false;
// runtimeQuit();
// }
// #endif
},
routes: [
...ROUTES,
{
path: '/',
redirect: (to) => {
return {
name: 'home'
}
}
},
{
path: '*',
redirect: (to) => {
return {
name: 'home'
}
}
},
]
});
export {
router,
RouterMount
}
page {
background-color: #F2F6F9;
}
uni-page-body,
html,
body {
height: 100%;
}
/*坑:解决iphoneX等大屏手机底部小黑条挡住tab的解决方法:安全区域距离底部边界距离env() 跟 constant() 需要同时存在,而且顺序不能换。*/
/* #ifdef H5 */
body,
.footer {
padding-bottom: constant(safe-area-inset-bottom);
/* 兼容 iOS < 11.2 */
padding-bottom: env(safe-area-inset-bottom);
/* 兼容 iOS >= 11.2 */
}
/* #endif */
view {
box-sizing: border-box;
}
image{
width: 100%;
height: 100%;
}
\ No newline at end of file
// 橙色渐变色
$orange-linear-gradient: linear-gradient(-45deg, #EB7A2F, #EB872F);
// 橙色字体
$orange-color:#EB872F;
// 默认字体黑色
$default-text-color:#2E2E2E;
// 底边框色
$default-border-color:#E1E4F5;
// 窗口背景色
$default-background-color:#FAF9F7;
/* 文字尺寸 */
$hs-font-size-sm:24upx;
$hs-font-size-base:28upx;
$hs-font-size-lg:32upx;
// 基础行高
$base-line-height:28upx;
.cl-waterfall {
width: 100%;
box-sizing: border-box;
overflow: hidden;
&-column {
float: left;
break-inside: avoid;
}
}
const getters = {
userinfo:state=>state.login.userinfo,
}
export default getters
import Vue from 'vue'
import Vuex from 'vuex'
import login from './modules/login'
import getters from './getters'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
login,
},
getters
})
export default store
import {
setToken,
setUserinfo,
getUserinfo,
removeToken,
removeUserinfo,
removeTimetamp,
setCodeTimetamp
} from "@/utils/common.js"
import {
loginInfo
} from "@/utils/config.js"
import {
userLogin,
getProfile,
getDVRHost,
getHeadImageHost,
subscribeCyzn
} from "@/api/login/index.js";
import {
wxLogin
} from "@/utils/auth.js"
const state = {
userinfo: getUserinfo(),
scene: null,
showPublic: false,
// 场景值
sceneList: [
1011,
1017,
1025,
1047,
1124,
// 1001,
// 1038,
// 1041,
// 1089,
// 1090,
// 1104,
// 1131,
// 1187,
],
systemInfo: null, // 系统信息
liveStatus:0
}
const mutations = {
SET_USERINFO: (state, data) => {
state.userinfo = data
},
SET_SCENE: (state, data) => {
state.scene = data
let flag = false
state.sceneList.forEach(item => {
if (item === data) {
flag = true
}
})
state.showPublic = flag
},
SET_SYSTEM_INFO: (state, data) => {
state.systemInfo = data
},
}
const actions = {
Set_scene({
commit
}, data) {
commit("SET_SCENE", data)
},
Login({
state,
commit,
dispatch
}) {
return new Promise((resolve, reject) => {
wxLogin().then(wechatCode => {
loginInfo.wechatCode = wechatCode
userLogin(loginInfo).then(res => {
let {
code,
data
} = res
if (code === 200) {
setCodeTimetamp()
setToken(data)
resolve(res)
} else {
reject()
}
}).catch(err => {
reject()
})
}).catch(err => {
reject()
})
})
},
// 获取用户信息
GetInfo({
commit,
state
}) {
return new Promise((resolve, reject) => {
getProfile().then(res => {
let {
code,
data
} = res
if (code === 200) {
setUserinfo(data)
commit("SET_USERINFO", data)
resolve(res)
} else {
reject()
}
}).catch(err => {
reject()
})
})
},
// 退出系统
LogOut({
commit,
state
}) {
removeToken()
removeUserinfo()
removeTimetamp()
},
// 获取图片域名
GetHost({
commit
}) {
if (getHost()) {
return false
}
getDVRHost().then(res => {
let {
code,
data
} = res
if (code === 200) {
let host = `https://${data}/`
commit("SET_HOST", host)
}
})
},
// 获取头像域名
Get_HeadImg_Host({
commit
}) {
if (getHeadImgHost()) {
return false
}
getHeadImageHost().then(res => {
let {
code,
data
} = res
if (code === 200) {
let host = `https://${data}/`
commit("SET_HEADIMGHOST", host)
}
})
},
// 获取系统信息
Get_system_info({
commit
}) {
uni.getSystemInfo({
success: res => {
commit("SET_SYSTEM_INFO", res)
}
});
},
// 检查用户是否已经关注公众号
Get_subscribeCyzn() {
return new Promise((resolve, reject) => {
subscribeCyzn().then(res => {
let {
code,
data
} = res
if (code === 200) {
resolve(data)
} else {
reject()
}
}).catch(err => {
reject()
})
})
},
}
export default {
state,
mutations,
actions
}
/**
* 这里是uni-app内置的常用样式变量
*
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
*
*/
/**
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
*
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
*/
/* 颜色变量 */
/* 行为相关颜色 */
$uni-color-primary: #007aff;
$uni-color-success: #4cd964;
$uni-color-warning: #f0ad4e;
$uni-color-error: #dd524d;
/* 文字基本颜色 */
$uni-text-color:#333;//基本色
$uni-text-color-inverse:#fff;//反色
$uni-text-color-grey:#999;//辅助灰色,如加载更多的提示信息
$uni-text-color-placeholder: #808080;
$uni-text-color-disable:#c0c0c0;
/* 背景颜色 */
$uni-bg-color:#ffffff;
$uni-bg-color-grey:#f8f8f8;
$uni-bg-color-hover:#f1f1f1;//点击状态颜色
$uni-bg-color-mask:rgba(0, 0, 0, 0.4);//遮罩颜色
/* 边框颜色 */
$uni-border-color:#c8c7cc;
/* 尺寸变量 */
/* 文字尺寸 */
$uni-font-size-sm:12px;
$uni-font-size-base:14px;
$uni-font-size-lg:16;
/* 图片尺寸 */
$uni-img-size-sm:20px;
$uni-img-size-base:26px;
$uni-img-size-lg:40px;
/* Border Radius */
$uni-border-radius-sm: 2px;
$uni-border-radius-base: 3px;
$uni-border-radius-lg: 6px;
$uni-border-radius-circle: 50%;
/* 水平间距 */
$uni-spacing-row-sm: 5px;
$uni-spacing-row-base: 10px;
$uni-spacing-row-lg: 15px;
/* 垂直间距 */
$uni-spacing-col-sm: 4px;
$uni-spacing-col-base: 8px;
$uni-spacing-col-lg: 12px;
/* 透明度 */
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
/* 文章场景相关 */
$uni-color-title: #2C405A; // 文章标题颜色
$uni-font-size-title:20px;
$uni-color-subtitle: #555555; // 二级标题颜色
$uni-font-size-subtitle:26px;
$uni-color-paragraph: #3F536E; // 文章段落颜色
$uni-font-size-paragraph:15px;
/* uni.scss */
@import 'uview-ui/theme.scss';
// 引入自定义全局scss变量
@import "@/static/styles/common.scss"
\ No newline at end of file
let localtionshowModal = null
import store from "@/store/index.js"
export function showModal({
content = "检测到您没打开获取位置信息功能权限,是否去设置打开?",
showCancel = true,
callback,
fail
}) {
if (localtionshowModal) {
return false;
}
localtionshowModal = setTimeout(() => {
uni.showModal({
content: content,
confirmText: '确认',
cancelText: '取消',
showCancel: showCancel,
success: res => {
if (res.confirm) {
if (callback && callback instanceof Function) {
callback()
}
} else {
console.log('取消');
if (fail && fail instanceof Function) {
fail()
}
}
},
complete: () => {
clearTimeout(localtionshowModal);
localtionshowModal = null;
}
});
}, 1);
}
export function openSetting({
callback,
scope = "scope.userLocation",
fail,
}) {
uni.openSetting({
success: res => {
if (res.authSetting[scope]) {
if (callback && callback instanceof Function) {
callback()
}
}else{
if (fail && fail instanceof Function) {
fail()
}
}
}
});
}
export const getLocation = function(callback) {
return new Promise((resolve, reject) => {
uni.authorize({
scope: 'scope.userLocation',
success: () => {
uni.getLocation({
type: 'gcj02', // 国测局坐标
success: res => {
resolve(res)
},
fail: err => {
reject(err)
}
});
},
fail: err => {
showModal({
callback() {
openSetting({
scope: "scope.userLocation",
callback
})
}
});
// console.log(err);
reject()
}
});
})
}
export const getWritePhotosAlbum = function() {
return new Promise((resolve, reject) => {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success: res => {
resolve(res)
},
fail: err => {
showModal({
content: "检测到您没打开保存照片到相册权限,是否去设置打开?",
callback() {
openSetting({
scope: "scope.writePhotosAlbum",
callback
})
}
});
// console.log(err);
}
});
})
}
export const wxLogin = function() {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin',
success: res => {
let {
errMsg,
code
} = res
if (errMsg === "login:ok") {
resolve(code)
}else{
reject()
}
},
fail: err => {
reject()
}
});
})
}
export const getCode = function() {
return new Promise((resolve, reject) => {
wxLogin().then(code => {
resolve(code)
}).catch(err => {
reject()
})
})
}
export const getUserinfo = function(callback) {
return new Promise((resolve, reject) => {
uni.authorize({
scope: 'scope.userInfo',
success: () => {
uni.getUserInfo({
success: res => {
resolve(res)
},
fail: err => {
// console.log(err);
reject(err)
}
});
},
fail: err => {
console.log(err);
showModal({
content: "检测到您没打开获取用户信息功能权限,是否去设置打开?",
callback() {
openSetting({
callback,
scope: "scope.userInfo"
})
}
})
reject()
}
});
})
}
export const authorizeUserinfo = function(scope="scope.userInfo") {
return new Promise((resolve, reject) => {
uni.authorize({
scope: scope,
success: res => {
uni.getUserInfo({
success: res => {
resolve(res)
},
fail: err => {
reject(err)
}
});
},
fail: err => {
reject(err)
}
});
})
}
import {
token,
TIMETAMP,
codeTimestamp,
userinfo,
headName,
} from "./config.js"
export function setToken(data) {
uni.setStorageSync(token, data);
let time = new Date().getTime()
uni.setStorageSync(TIMETAMP, time);
}
export function getToken() {
return uni.getStorageSync(token) || ""
}
export function removeToken() {
uni.removeStorageSync(token);
uni.removeStorageSync(TIMETAMP);
uni.removeStorageSync(userinfo);
}
export function setTimetamp() {
let time = new Date().getTime()
uni.setStorageSync(TIMETAMP, time);
}
export function getTimetamp() {
return uni.getStorageSync(TIMETAMP) || ""
}
export function removeTimetamp() {
uni.removeStorageSync(TIMETAMP);
}
export function setCodeTimetamp() {
let time = new Date().getTime()
uni.setStorageSync(codeTimestamp, time);
}
export function getCodeTimetamp() {
return uni.getStorageSync(codeTimestamp) || ""
}
export function removeCodeTimetamp() {
uni.removeStorageSync(codeTimestamp);
}
export function setUserinfo(data) {
uni.setStorageSync(userinfo, data);
}
export function getUserinfo() {
return uni.getStorageSync(userinfo) || {}
}
export function removeUserinfo() {
uni.removeStorageSync(userinfo);
}
export function checkPhone() {
let userinfo = getUserinfo()
let {
phone
} = userinfo
if (!phone) {
return false
} else {
return true;
}
}
export function checkNickname() {
let userinfo = getUserinfo()
let {
nickname,
headImgUrl
} = userinfo
if (!nickname || headImgUrl === "default/headimg01.png") {
return false
} else {
return true;
}
}
export function checkToken() {
let time = new Date().getTime()
let backToken = getToken()
let backTime = uni.getStorageSync(TIMETAMP)
if (backToken) {
if (backTime && time - backTime <= 24 * 60 * 60 * 1000) {
return true;
} else {
removeUserinfo()
removeToken()
return false;
}
} else {
removeUserinfo()
removeToken()
return false;
}
}
export function checkAdminToken() {
let time = new Date().getTime()
let {check,expireTime,headName,token}=getPasswordCheck()
if (check&&token) {
if (expireTime && time < expireTime) {
return true;
} else {
removePasswordCheck()
return false;
}
} else {
removePasswordCheck()
return false;
}
}
export function checkCodeTimetamp() {
let time = new Date().getTime()
let backTime = getCodeTimetamp()
if (backTime) {
if (time - backTime <= 2 * 60 * 60 * 1000) {
return true;
} else {
removeCodeTimetamp()
return false;
}
} else {
return false;
}
}
// 自定义filter
export function myFilter(value, options) {
if (options && options instanceof Array) {
let arr = options.filter(item => item.value === value)
if (arr.length) {
return arr[0] && arr[0].label
} else {
return value
}
} else {
return value
}
}
// 自定义弹框消息
export function showToast(message) {
uni.showToast({
title: message,
icon: 'none',
// mask: true
})
}
// 从path获取.后缀名 例如: .png
export function get_suffix(filename, noPoint) {
let pos = filename.lastIndexOf('.');
let suffix = '';
if (pos != -1) {
if (noPoint) {
pos += 1
}
suffix = filename.substring(pos);
}
return suffix;
}
// 从base64文件中去后缀名
export function getSuffixname(base64) {
if (base64) {
let startIndex = base64.indexOf('/');
if (startIndex >= 0) {
let endIndex = base64.indexOf(';');
if (endIndex >= 0) {
let suffixName = base64.substring(startIndex + 1, endIndex);
return suffixName;
}
return '';
}
return '';
}
return '';
}
// imageBase64转Blob
export function base64ToBlob(base64) {
let arr = base64.split(',');
let mime = arr[0].match(/:(.*?);/)[1];
let bstr = atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {
type: mime
});
}
// blob转file文件
export function blobToFile(blob, fileName) {
blob.lastModifiedDate = new Date();
blob.name = fileName;
return blob;
}
// base64转file文件
export function base64toFile(dataurl, filename) { //将base64转换为文件
var arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {
type: mime
});
}
// 设置随机文件名 len
export function random_string(len = 32) {
let chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
let maxPos = chars.length;
let pwd = '';
for (let i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
// 全局判断是否IOS方法
export function isIos() {
const u = navigator.userAgent;
return u.indexOf("iPhone") > -1 || u.indexOf("Mac OS") > -1;
}
// 日期格式化
export function parseTime(time, pattern) {
if (arguments.length === 0 || !time) {
return null
}
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
} else if (typeof time === 'string') {
time = time.replace(new RegExp(/-/gm), '/');
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
export const getTime = function(time) {
var myDate = new Date(time);
// var u = navigator.userAgent;
// var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
// var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
let isiOS = uni.getSystemInfoSync().platform === "ios" ? true : false
let t = ""
if (isiOS) {
if (typeof(time) === "string") {
t = new Date(time.replace(/-/g, '/')).getTime();
}
t = myDate.getTime();
} else {
t = myDate.getTime();
}
return t;
}
export const baseURL="/baseapi"
export const token="TOKEN"
export const PHONENUMBER="PHONENUMBER"
export const TIMETAMP="TIMETAMP"
export const codeTimestamp="CODETIMESTAMP"
export const userinfo="USERINFO"
export const headName = 'admin-token';
export const temperature = 'TEMPERATURE';
export const appid="wx55e75ad85611191f"
// export const API_HOST = ''; // 正式服
export const API_HOST = ''; // 测试服
export const OSSBaseUrl = ''; // 阿里云OSS图片地址
export const IMG_HOST = ''; // 服务器线上图片地址
export const STATIC_IMG_HOST = ''; // 服务器静态图片地址
export const loginInfo = {
"faceBase64": "",
"faceFeatureStr": "",
"faceGroupId": "",
"fingerprint": "",
"fingerprintGroupId": "",
"applicationType":3,
"flag": 8,
"password": "",
"phone": "",
"phoneCode": "",
"username": "",
"wechatCode": "",
"wechatScope": ""
}
\ No newline at end of file
// 获取元素高度
export const getViewHeight = (select, callback) => {
let content = uni.createSelectorQuery().select(select);
content
.boundingClientRect(function(data) {
const contentHeight = data.height; // 获取元素高度
let height = contentHeight;
callback(height)
})
.exec();
}
// 是否Array类型
export function isArray(value) {
if (typeof Array.isArray === "function") {
return Array.isArray(value);
} else {
return Object.prototype.toString.call(value) === "[object Array]";
}
}
// 是否Object类型
export function isObject(value) {
return Object.prototype.toString.call(value) === "[object Object]";
}
// 是否Function类型
export function isFunction(value) {
return typeof value === "function";
}
// 是否String类型
export function isString(value) {
return typeof value === "string";
}
// 是否null类型
export function isNull(value) {
return !value && value !== 0;
}
// 是否Boolean类型
export function isBoolean(value) {
return typeof value === "boolean";
}
// 是否数字类型
export function isNumber(value) {
return typeof value === "number" && !isNaN(value);
}
// 是否Promise类型
export function isPromise(obj) {
obj !== null &&
(typeof obj === "object" || typeof obj === "function") &&
typeof obj.then === "function";
}
// 是否为空
export function isEmpty(value) {
if (isArray(value)) {
return value.length === 0;
}
if (isObject(value)) {
return Object.keys(value).length === 0;
}
return value === "" || value === undefined || value === null;
}
// 取最后一个值
export function last(data) {
if (isArray(data) || isString(data)) {
return data[data.length - 1];
}
}
// 比较值
export function compareValue(a, b) {
return String(a) === String(b);
}
// 深拷贝
export function cloneDeep(v) {
if (isObject(v)) {
let d = {}
for (let k in v) {
if (v.hasOwnProperty && v.hasOwnProperty(k)) {
if (v[k] && typeof v[k] === "object") {
d[k] = cloneDeep(v[k]);
} else {
d[k] = v[k];
}
}
}
return d
} else if (isArray(v)) {
return v.map(cloneDeep);
} else {
return v
}
}
// 深度合并
export function deepMerge(a, b) {
let k;
for (k in b) {
a[k] =
a[k] && a[k].toString() === "[object Object]" ? deepMerge(a[k], b[k]) : (a[k] = b[k]);
}
return a;
}
// 获取当前页面信息
export function getCurrentPage() {
const { route, $page, options, $route } = last(getCurrentPages());
return {
path: `/${route}`,
fullPath: $page.fullPath,
// #ifdef MP
query: options,
// #endif
// #ifdef H5
query: $route.params
// #endif
};
}
/**
* 解析rpx
* @param {*} val
*/
export function parseRpx(val) {
return isArray(val) ? val.map(parseRpx).join(" ") : (isNumber(val) ? val + "rpx" : val);
}
/**
* 获取父级节点
* @param {*} name componentName
* @param {*} keys 保留的参数,避免 computed 非 H5 解析失败
*/
export function getParent(name, keys) {
let parent = this.$parent;
while (parent) {
if (parent.$options.componentName !== name) {
parent = parent.$parent;
} else {
return keys.reduce((result, key) => {
result[key] = parent[key];
return result;
}, {});
}
}
return null;
}
/**
* 获取当前颜色
*
* @param {*} { color, max, value }
*/
export function getCurrentColor({ color, max, value }) {
if (isString(color)) {
return color;
} else {
const colorArray = color
.map((item, index) => {
if (isString(item)) {
return {
color: item,
value: (index + 1) * (max / color.length)
};
}
return item;
})
.sort((a, b) => a.value - b.value);
for (let i = 0; i < colorArray.length; i++) {
if (colorArray[i].value >= value) {
return colorArray[i].color;
}
}
return colorArray[colorArray.length - 1].color;
}
}
// 个人中心菜单
export const packageOptions = [{
id: 1,
title: '我的消息',
icon: '/static/images/me/my_message@2x.png',
path: "/pages/me/my-message/my-message"
},
{
id: 2,
title: '我的车辆',
icon: '/static/images/me/my_car@2x.png',
path: "/pages/me/my-car/my-car"
},
{
id: 3,
title: '帮助中心',
icon: '/static/images/me/help_center@2x.png',
path: "/pages/me/help-center/help-center"
},
{
id: 4,
title: '设置',
icon: '/static/images/me/set@2x.png',
path: "/pages/me/setting/setting"
},
]
import {
API_HOST,
headName,
baseURL
} from "./config.js"
import {
setToken,
getToken,
removeToken,
checkToken,
getUserinfo,
removeUserinfo,
setTimetamp,
removeTimetamp,
showToast
} from "./common.js"
import store from "@/store/index.js"
function request({
url,
method = 'GET',
data,
noLoading = false,
header = {
'Content-type': 'application/json;charset=utf-8'
},
noBase = false
}) {
if (method.toLowerCase() == 'post') {
header['Content-type'] = header['Content-type'] ? header['Content-type'] : 'application/json;charset=utf-8'
}
let token = getToken()
// #ifdef H5
if (process.env.NODE_ENV === 'development') {
if (!noBase) {
url = baseURL + url
}
}
// #endif
// #ifndef H5
url = API_HOST + url
// #endif
console.log("requestUrl=" + url)
// console.log("请求参数===")
// console.log(data)
header["Authorization"] = token
if (!noLoading) {
uni.showLoading({
title: '加载中',
mask: true
});
}
return new Promise((resolve, reject) => {
uni.request({
method,
url: url,
data,
header,
success: res => {
// 重置时间戳
setTimetamp()
// console.log(res)
if (res.data.code === 200) {
if (!noLoading) {
uni.hideLoading()
}
resolve(res.data)
} else {
uni.hideLoading()
if (res.data.code === 23007||res.data.code === 23009) {
if (url.indexOf("customer/logout") !== -1) {
resolve(res.data)
} else {
console.log("未登录或者登陆已过期")
resolve(res.data)
store.dispatch("LogOut")
uni.switchTab({
url:"/pages/index/index"
})
}
} else if (res.data.code === 23001) {
resolve(res.data)
} else {
showToast(res.data.msg)
resolve(res.data)
}
}
},
fail: error => {
// 重置时间戳
setTimetamp()
uni.hideLoading()
showToast("request error")
console.log(error)
reject(error)
}
})
})
}
export default request
export const tabbar = [{
"pagePath": "/pages/index/index",
"iconPath": "/static/image/index/service_unclick@2x.png",
"selectedIconPath": "/static/image/index/service_click@2x.png",
"text": "首页"
}, {
"pagePath": "/pages/index/schedule",
"iconPath": "/static/image/index/control_car_gray@2x.png",
"selectedIconPath": "/static/image/index/control_car_click@2x.png",
"text": "行程"
},{
"pagePath": "/pages/index/account",
"iconPath": "/static/image/index/tianj@2x.png",
"selectedIconPath": "/static/image/index/tianj@2x.png",
"text": "",
"midButton": true
}, {
"pagePath": "/pages/index/bill",
"iconPath": "/static/image/index/service_unclick@2x.png",
"selectedIconPath": "/static/image/index/service_click@2x.png",
"text": "账单"
}, {
"pagePath": "/pages/index/mine",
"iconPath": "/static/image/index/personal_center_unclick@2x.png",
"selectedIconPath": "/static/image/index/personal_center_click@2x.png",
"text": "我的"
}]
//vue.config.js
const TransformPages = require('uni-read-pages')
const {webpack} = new TransformPages()
module.exports = {
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
ROUTES: webpack.DefinePlugin.runtimeValue(() => {
const tfPages = new TransformPages({
includes: ['path', 'name', 'aliasPath']
});
return JSON.stringify(tfPages.routes)
}, true )
})
]
}
}
\ No newline at end of file
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