zhengkaixin hace 4 años
padre
commit
9fd7c9a5d6

+ 10 - 5
README.md

@@ -41,8 +41,13 @@ www  WEB部署目录(或者子目录)
 ##插件引用
 #控制台
 yarn add vconsole
-#uniapp 路由站
-npm install uni-simple-router uni-read-pages
-#store
-yarn add vuex
-yarn add weixin-js-sdk
+###uniapp 路由站
+npm install uni-simple-router uni-read-pages(取消使用, 存在h5 刷新白屏问题)
+//双路由   uni-crazy-router 直接链接访问, 无法触发前置占点
+[uni-crazy-router](https://ext.dcloud.net.cn/plugin?id=1658)
+[bobo-router ](https://ext.dcloud.net.cn/plugin?id=904)
+
+
+
+[vue-router-uni ](https://ext.dcloud.net.cn/plugin?id=605)
+[mac80端口问题无法使用](https://blog.csdn.net/weixin_41047933/article/details/97765502)

+ 153 - 0
bobo-router/README.md

@@ -0,0 +1,153 @@
+# bobo-router
+
+bobo-router 是一个基于uni-app框架的路由拦截插件,本项目借鉴了[uni-simple-router](https://github.com/SilurianYang/uni-simple-router)的思路,并对其进行简化,简化的原因是因为自己比较懒,不想每次新增页面就定义两遍路由表,所以`bobo-router`的特点就是纯粹的路由拦截,不再**定义两遍路由表**。
+
+当然,由于不再定义路由表,也损失了一些能力,比如不能使用命名路由,不能在路由表中自定义路由元信息等。
+
+> 本人不是大神,插件可能会存在各种各样的问题,望大家谨慎使用,并多多担待。
+
+## 安装
+
+下载插件后,在`main.js`中导入即可。
+
+```js
+// main.js
+
+import router from './utils/bobo-router'
+```
+
+## 基本使用
+
+同`uni-simple-router`一样,项目中的路由跳转要全部弃用`uni.navigateTo()`这样的系统跳转方法,转而使用插件提供的`this.$Router.push()`这样的方法。
+
+```js
+// *.vue
+
+// 跳转页面,保留当前页到页面栈,等同于 uni.navigateTo()
+this.$Router.push({
+	page: '/pages/index/index',
+	params: {}
+})
+
+// 跳转页面,替换当前页到页面栈,等同于 uni.redirectTo()
+this.$Router.replace({
+	page: '/pages/index/index',
+	params: {}
+})
+
+// 跳转页面,清空页面栈,等同于 uni.reLaunch()
+this.$Router.replaceAll({
+	page: '/pages/index/index',
+	params: {}
+})
+
+// 跳转 Tabbar,等同于 uni.switchTab()
+this.$Router.pushTab({
+	page: '/pages/index/index',
+	params: {}
+})
+```
+
+> Tips: 
+> 如果不需要传递参数,可以直接使用 this.$Router.push('/pages/index/index')
+
+> 注意:
+> pushTab传递的参数可通过this.$Route.params获取,但h5页面刷新之后就会丢失数据
+
+## 路由拦截
+
+支持路由前置守卫和路由后置守卫,并且提供一个路由跳转失败的回调,可以重写以实现自己的逻辑。
+
+在`bobo-router/index.js`中添加自己的拦截逻辑。
+
+```js
+// ./utils/bobo-router/index.js
+
+// 路由全局拦截器 在这里处理登录、授权等相关操作
+router.beforeEach(function(to, from, next) {
+	console.log('前置守卫')
+	// to.page不存在表示此次路由跳转仅为了执行路由守卫,若不需处理则直接放行,就不会执行任何路由操作了
+	if (from.page === '/pages/plugin/routers/r3' && !to.page) {
+	// 测试小程序跳转
+	// if (from.page === '/pages/index/index' && !to.page) {
+		next({page: '/pages/plugin/routers/r4', params: {
+			message: '我是从路由3刷新跳过来的'
+		}, method: 'redirectTo'})
+	} else {
+		next()
+	}
+})
+
+// 路由后置拦截器 在这里处理用户高频操作信息
+router.afterEach(function (to, from) {
+	console.log('后置守卫')
+})
+
+// 路由跳转出错处理
+router.onError(function(e) {
+	console.log('错误:', e.message || '路由跳转失败')
+})
+```
+
+参数解释:
+
+**to**:目标路由信息,包含`method`路由跳转方式、`page`页面地址和`params`页面参数
+
+> 注:在进入应用的第一个页面或h5刷新页面后会执行路由前置守卫,此时 to 中的属性均为 undefined
+
+**from**:当前路由信息,包含`page`页面地址和`params`页面参数
+
+**next**:下一步操作
+
+- `next(false)` 中断路由跳转
+- `next('/pages/index/index')` 执行指定页面的路由前置守卫,若当前操作指定过跳转方式,则使用该跳转方式,否则使用默认的push进行跳转
+- `next({page:'/pages/index/index',params:{},method:''})` 执行指定页面的路由前置守卫,method传入跳转方式,也可以不指定,效果同直接传入页面地址
+- `next()` 放行 执行跳转操作
+
+## 参数解析
+
+使用本插件的方法去跳转路由,会将对象的第一级属性转换到URL中,深层对象则转为json串放在对应的属性中。
+
+例如:
+
+```js
+// 转换前对象
+{
+	num: 19,
+	numStr: '19',
+	testParams: true,
+	deepObj: {
+		str: 'hahaha'
+	},
+	ignoreFun: function() {
+		console.log('i\'m hide.')
+	},
+	testUndefined: undefined,
+	testNull: null
+}
+
+// 转换后URL
+?num=19&numStr=19&testParams=true&deepObj=%7B"str"%3A"hahaha"%7D&testUndefined=&testNull=
+```
+
+如果要获取当前路由信息,可通过`this.$Route`获取。
+
+```js
+{
+    "path": "/pages/plugin/router?num=19&numStr=19&testParams=true&deepObj={\"str\":\"hahaha\"}&testUndefined=&testNull=",
+    "params": {
+        "num": 19,
+        "numStr": "19",
+        "testParams": true,
+        "deepObj": {
+            "str": "hahaha"
+        },
+        "testNull": null
+    },
+    "page": "/pages/plugin/router",
+    "pageTitle": "路由拦截插件"
+}
+```
+
+> 页面标题 pageTitle 是在页面中的 data(){}代码块中定义了之后才能正常显示,且只能在onload生命周期之后使用。
+> h5端则不需要定义pageTitle,插件可直接获取当前网页标题。

+ 362 - 0
bobo-router/bobo-router.js

@@ -0,0 +1,362 @@
+class Router {
+	constructor(arg) {
+		if (arg && arg.constructor !== Object) {
+			return console.error(`Routing configuration must be an Object`)
+		}
+		Router.$root = this;
+	}
+
+	// 路由跳转方法映射
+	routeMap = {
+		push: 'navigateTo',
+		replace: 'redirectTo',
+		replaceAll: 'reLaunch',
+		pushTab: 'switchTab'
+	}
+
+	/**
+	 * 执行路由跳转
+	 */
+	_pushTo() {
+		return new Promise((resolve, reject) => {
+			let {
+				page,
+				params,
+				method
+			} = this.tempRoute
+			// 对首次进入页面执行路由守卫时如果放行,method page params都为空 此时应该直接中断流程,无需抛出异常
+			if (!method && !page && !params) {
+				return
+			}
+
+			let urlParams = '?'
+			if (!page) {
+				reject(new Error('参数page未填写'))
+				return
+			} else if (params && typeof(params) === 'object') {
+				// 处理参数,转换为url字符串
+				Object.keys(params).forEach(k => {
+					// 深度对象转为json字符串(包含数组)
+					if (typeof(params[k]) === 'object') {
+						if (params[k]) {
+							const json = JSON.stringify(params[k])
+							urlParams += `${k}=${json}&`
+						} else {
+							urlParams += `${k}=&`
+						}
+					} else if (typeof(params[k]) === 'number' || typeof(params[k]) === 'string' || typeof(params[k]) ===
+						'boolean') {
+						// 基础值直接写入
+						urlParams += `${k}=${params[k]}&`
+					} else if (typeof(params[k]) === 'undefined') {
+						urlParams += `${k}=&`
+					}
+				})
+			}
+
+			// 参数组装
+			if (urlParams.length === 1) {
+				urlParams = ''
+			} else {
+				urlParams = urlParams.substr(0, urlParams.length - 1)
+			}
+
+			// 设置路由跳转方式
+			if (!method) {
+				method = 'navigateTo'
+			}
+			if (this.routeMap[method]) {
+				method = this.routeMap[method]
+			}
+
+			// 调用系统跳转方法
+			uni[method]({
+				url: page + urlParams,
+				success: () => {
+					// 执行路由后置守卫
+					if (this._afterEach && typeof(this._afterEach) === 'function') {
+						this._afterEach.call(this, this.tempRoute, this.route)
+					}
+
+					// 更新路由信息
+					this.route = {
+						path: page + urlParams,
+						params: params || {},
+						page
+					}
+					this.tempRoute = null
+					resolve()
+				},
+				fail: (e) => {
+					reject(new Error('路由跳转失败!'))
+				}
+			})
+		})
+	}
+
+	/**动态的导航到一个新 URL 保留浏览历史
+	 * navigateTo
+	 * @param {Object} rule
+	 */
+	push(arg) {
+		const rule = {
+			method: 'navigateTo'
+		}
+		if (typeof(arg) === 'string') {
+			rule.page = arg
+		} else if (typeof(arg) === 'object') {
+			rule.page = arg.page
+			rule.params = arg.params
+		}
+		this.next(rule)
+	}
+
+	/**动态的导航到一个新 URL 关闭当前页面,跳转到的某个页面。
+	 * redirectTo
+	 * @param {Object} rule
+	 */
+	replace(arg) {
+		const rule = {
+			method: 'redirectTo'
+		}
+		if (typeof(arg) === 'string') {
+			rule.page = arg
+		} else if (typeof(arg) === 'object') {
+			rule.page = arg.page
+			rule.params = arg.params
+		}
+		this.next(rule)
+	}
+
+	/**动态的导航到一个新 URL 关闭所有页面,打开到应用内的某个页面
+	 * 	reLaunch
+	 * @param {Object} rule
+	 */
+	replaceAll(arg) {
+		const rule = {
+			method: 'reLaunch'
+		}
+		if (typeof(arg) === 'string') {
+			rule.page = arg
+		} else if (typeof(arg) === 'object') {
+			rule.page = arg.page
+			rule.params = arg.params
+		}
+		this.next(rule)
+	}
+
+	/** 跳转Tabbar
+	 * 	switchTab
+	 * @param {Object} rule
+	 */
+	pushTab(arg) {
+		const rule = {
+			method: 'switchTab'
+		}
+		if (typeof(arg) === 'string') {
+			rule.page = arg
+		} else if (typeof(arg) === 'object') {
+			rule.page = arg.page
+			rule.params = arg.params
+		}
+		this.next(rule)
+	}
+
+
+	/**
+	 * 返回到指定层级页面上
+	 */
+	back(delta = 1) {
+		// 返回上级
+		if (delta.constructor != Number) {
+			this._errorHandler(new Error('返回层级参数必须是一个Number类型且必须大于0:'))
+			return
+		}
+		uni.navigateBack({
+			delta
+		})
+	}
+
+	/**
+	 * 分发路由
+	 * @param {Object} args
+	 */
+	_next() {
+		return new Promise((resolve, reject) => {
+			if (this._beforeEach && typeof(this._beforeEach) === 'function') {
+				// 需要传给守卫 to from next
+				this._beforeEach.call(this, this.tempRoute, this.route, resolve)
+			} else {
+				this._pushTo().catch(e => {
+					reject(e)
+				})
+			}
+		})
+	}
+
+	next(args) {
+		if (args) {
+			// 保存临时数据
+			if (typeof(args) === 'object') {
+				this.tempRoute = {
+					// 第一次调用next一定存在method,后续循环调用可能不会存在,不存在时使用上次缓存的method
+					method: args.method || this.tempRoute.method,
+					page: args.page,
+					params: args.params
+				}
+			} else if (typeof(args) === 'string') {
+				this.tempRoute = {
+					page: args
+				}
+			} else if (!args) {
+				// 中断路由 args = false
+				this.tempRoute = null
+				return
+			}
+
+			if (!this.route) {
+				this.route = {
+					page: '/' + getCurrentPages()[0].route
+				}
+			}
+
+			this._next().then(args => {
+				this.next(args)
+			}).catch(e => {
+				this.tempRoute = null
+				this._errorHandler(e)
+			})
+		} else {
+			this._pushTo().catch(e => {
+				this.tempRoute = null
+				this._errorHandler(e)
+			})
+		}
+	}
+
+	/**
+	 * 应用启动时执行一次路由检查(前置守卫,若通过则不做事情)
+	 */
+	doBeforeHooks() {
+		this.tempRoute = {}
+		this.next({})
+	}
+
+	// 设置路由前置/后置守卫
+	beforeEach(fn) {
+		this._beforeEach = fn
+	}
+	afterEach(fn) {
+		this._afterEach = fn
+	}
+	// 设置路由跳转错误处理
+	onError(fn) {
+		if (fn && typeof(fn) === 'function') {
+			this._errorHandler = fn
+		}
+	}
+
+	// 获取当前路由信息
+	getCurrentRoute() {
+		return this.route
+	}
+
+}
+
+// 路由对象属性定义
+Router.$root = null
+// 当前路由内容
+Router.route = null
+// 临时路由信息
+Router.tempRoute = null
+// 路由前置后置守卫
+Router._beforeEach = null
+Router._afterEach = null
+// 路由跳转错误处理
+Router._errorHandler = function(e) {
+	console.error(e)
+}
+
+Router.install = function(Vue) {
+	Vue.mixin({
+		onLaunch: function() {},
+		onLoad: function(props) {
+			// 首次进入页面时,缓存中不存在当前路由信息,需要初始化路由信息
+			if (!Router.$root.getCurrentRoute()) {
+				const rt = {
+					params: {},
+					page: '/' + getCurrentPages()[0].route
+				}
+				if (props) {
+					Object.keys(props).forEach(k => {
+						// url转的对象全部都是字符串,需要识别其中的对象和基本数据类型
+						try {
+							const obj = JSON.parse(props[k])
+							if (typeof(obj) === 'string') {
+								// 只有字符串还会是字符串,数字、布尔、数组均会转换为正常类型
+								rt.params[k] = props[k]
+							} else {
+								rt.params[k] = obj
+							}
+						} catch (e) {
+							rt.params[k] = props[k]
+						}
+					})
+				}
+				Router.$root.route = rt
+
+				// 执行路由前置守卫
+				Router.$root.doBeforeHooks()
+			}
+
+			// 自动获取页面标题(app端可能获取不到)
+			const pages = getCurrentPages()
+			let pageTitle = pages[pages.length - 1].pageTitle
+			// #ifdef H5
+			if (!pageTitle) {
+				pageTitle = document.title
+			}
+			// #endif
+			Router.$root.route.pageTitle = pageTitle
+		},
+
+		onShow() {
+			if (!getCurrentPages().length) {
+				return
+			}
+			// 获取当前路由信息
+			const pages = getCurrentPages()
+			const page = pages[pages.length - 1]
+			let pageTitle = page.pageTitle
+			const rt = {
+				params: {},
+				page: '/' + page.route,
+			}
+			if (!pageTitle) {
+				// #ifdef H5
+				rt.pageTitle = document.title
+				// #endif
+			} else {
+				rt.pageTitle = pageTitle
+			}
+			
+			const route = Router.$root.route
+			// 若当前页面地址不等于缓存中地址,则更新缓存路由信息
+			if (!route || route.page !== rt.page) {
+				Router.$root.route = rt
+			}
+		}
+	})
+	Object.defineProperty(Vue.prototype, "$Router", {
+		get: function() {
+			return Router.$root
+		}
+	})
+	Object.defineProperty(Vue.prototype, "$Route", {
+		get: function() {
+			return Router.$root.getCurrentRoute()
+		}
+	})
+}
+
+export default Router

+ 56 - 0
bobo-router/index.js

@@ -0,0 +1,56 @@
+import Vue from 'vue'
+import uniCrazyRouter from "uni-crazy-router";
+Vue.use(uniCrazyRouter)
+//** 有bug, 第一次直接敲链接访问, 是访问bobo-router 前置守卫
+//**  后续操作,访问的是 uniCrazyRouter的前置守卫
+
+
+uniCrazyRouter.beforeEach(async (to, from ,next)=>{
+    // 逻辑代码
+console.log("beforeEach")
+    next()
+})
+
+uniCrazyRouter.afterEach((to, from)=>{
+    // 逻辑代码
+	console.log("afterEach")
+})
+
+uniCrazyRouter['on'+'Error']((to, from)=>{
+    // 逻辑代码
+	console.log("Error")
+})
+
+import Router from './bobo-router'
+
+Vue.use(Router)
+
+// 路由配置 页面中全部使用this.$Router来操作路由,以实现路由的全局管理
+const router = new Router()
+
+// 路由全局拦截器 在这里处理登录、授权等相关操作
+router.beforeEach(function(to, from, next) {
+	console.log('前置守卫')
+	// to.page不存在表示此次路由跳转仅为了执行路由守卫,若不需处理则直接放行,就不会执行任何路由操作了
+	if (from.page === '/pages/plugin/routers/r3' && !to.page) {
+	// 测试小程序跳转
+	// if (from.page === '/pages/index/index' && !to.page) {
+		next({page: '/pages/plugin/routers/r4', params: {
+			message: '我是从路由3刷新跳过来的'
+		}, method: 'replace'})
+	} else {
+		next()
+	}
+})
+
+// 路由后置拦截器
+router.afterEach(function (to, from) {
+	console.log('后置守卫')
+})
+
+// 路由跳转出错处理
+router.onError(function(e) {
+	console.log('错误:', e.message || '路由跳转失败')
+})
+
+export default router

+ 3 - 1
main.js

@@ -2,7 +2,9 @@ import Vue from 'vue'
 import App from './App'
 import * as mixin from './utils/mixin.js'
 import Vconsole from 'vconsole'
- 
+ //import './router' // 引入路由
+ import router from './bobo-router'
+
 
 // main.js
 import uView from "uview-ui";

+ 7 - 1
manifest.json

@@ -70,7 +70,13 @@
     },
     "h5" : {
         "devServer" : {
-            "port" : 80
+            "port" : 8080,
+            "https" : true
+        },
+        "optimization" : {
+            "treeShaking" : {
+                "enable" : true
+            }
         }
     }
 }

+ 4 - 0
node_modules/.yarn-integrity

@@ -6,8 +6,10 @@
   "flags": [],
   "linkedModules": [],
   "topLevelPatterns": [
+    "compression-webpack-plugin@^7.1.2",
     "node-sass@^5.0.0",
     "sass-loader@^11.0.1",
+    "uni-crazy-router@0.0.31",
     "uni-read-pages@^1.0.5",
     "uni-simple-router@^2.0.1",
     "uview-ui@^1.8.4",
@@ -165,6 +167,7 @@
     "commander@^2.9.0": "https://registry.npm.taobao.org/commander/download/commander-2.20.3.tgz?cache=0&sync_timestamp=1616364569946&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33",
     "commander@^7.0.0": "https://registry.npm.taobao.org/commander/download/commander-7.2.0.tgz?cache=0&sync_timestamp=1616364569946&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcommander%2Fdownload%2Fcommander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7",
     "commondir@^1.0.1": "https://registry.npm.taobao.org/commondir/download/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b",
+    "compression-webpack-plugin@^7.1.2": "https://registry.npm.taobao.org/compression-webpack-plugin/download/compression-webpack-plugin-7.1.2.tgz?cache=0&sync_timestamp=1612085346866&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcompression-webpack-plugin%2Fdownload%2Fcompression-webpack-plugin-7.1.2.tgz#f9a1ba84d4879693e29726f6884b382940876597",
     "concat-map@0.0.1": "https://registry.npm.taobao.org/concat-map/download/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b",
     "concat-stream@^1.5.0": "https://registry.npm.taobao.org/concat-stream/download/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34",
     "config-chain@^1.1.11": "https://registry.npm.taobao.org/config-chain/download/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa",
@@ -629,6 +632,7 @@
     "uglify-js@^3.1.4": "https://registry.npm.taobao.org/uglify-js/download/uglify-js-3.13.3.tgz?cache=0&sync_timestamp=1616975826230&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fuglify-js%2Fdownload%2Fuglify-js-3.13.3.tgz#ce72a1ad154348ea2af61f50933c76cc8802276e",
     "uid@0.0.2": "https://registry.npm.taobao.org/uid/download/uid-0.0.2.tgz#5e4a5d4b78138b4f70f89fd3c76fc59aa9d2f103",
     "unbzip2-stream@^1.0.9": "https://registry.npm.taobao.org/unbzip2-stream/download/unbzip2-stream-1.4.3.tgz#b0da04c4371311df771cdc215e87f2130991ace7",
+    "uni-crazy-router@0.0.31": "https://registry.npm.taobao.org/uni-crazy-router/download/uni-crazy-router-0.0.31.tgz#14c2aa52fdef275b32504c8ba5257bf4585182e3",
     "uni-read-pages@^1.0.5": "https://registry.npm.taobao.org/uni-read-pages/download/uni-read-pages-1.0.5.tgz#452c8dcaa8977bbaef600909be926c8d9704387c",
     "uni-simple-router@^2.0.1": "https://registry.npm.taobao.org/uni-simple-router/download/uni-simple-router-2.0.1.tgz#99cd2467c7672936b53ba83af085806d171751bd",
     "unique-filename@^1.1.1": "https://registry.npm.taobao.org/unique-filename/download/unique-filename-1.1.1.tgz#1d69769369ada0583103a1e6ae87681b56573230",

+ 5 - 0
package-lock.json

@@ -2897,6 +2897,11 @@
       "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.2.3.tgz",
       "integrity": "sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw=="
     },
+    "uni-crazy-router": {
+      "version": "0.0.31",
+      "resolved": "https://registry.npmjs.org/uni-crazy-router/-/uni-crazy-router-0.0.31.tgz",
+      "integrity": "sha512-l+KTa/mJo/R/+u2zhvJuajL3xpzvwesohNm89Xqs+73l7NQGtsXhjNQ8zokYwGeXsmQaa2nRbwXD+zvgCZZ7dQ=="
+    },
     "uni-read-pages": {
       "version": "1.0.5",
       "resolved": "https://registry.npmjs.org/uni-read-pages/-/uni-read-pages-1.0.5.tgz",

+ 2 - 0
package.json

@@ -6,6 +6,8 @@
   "test": "vue-cli-service build --mode test"
  },
  "dependencies": {
+  "compression-webpack-plugin": "^7.1.2",
+  "uni-crazy-router": "0.0.31",
   "uni-read-pages": "^1.0.5",
   "uni-simple-router": "^2.0.1",
   "uview-ui": "^1.8.4",

+ 8 - 1
pages.json

@@ -243,7 +243,14 @@
 			"name": "404"
 		}
         
-    ],
+    ],
+	"condition": { //模式配置,仅开发期间生效
+	        "current": 0, //当前激活的模式(list 的索引项)
+	        "list": [{
+	            "name": "test", //模式名称
+	            "path": "pages/buytickets/index" //启动页面,必选
+	        }]
+	    },
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
 		"navigationBarTitleText": "uni-app",

+ 32 - 15
pages/buytickets/index.js

@@ -1,16 +1,33 @@
-
-
-	export default {
-		data() {
-			return {
-			
-			}
-		},
-		methods: {
-			
-		},
-		onLoad() {
-			 
+export default {
+    data() {
+        return {
+      id:0, // 使用 marker点击事件 需要填写id
+            title: 'map',
+  
+			longitude: 112.276527,
+			latitude: 30.306427,
+            covers: [{
+               longitude: 112.276527,
+               latitude: 30.306427,
+               iconPath: '/static/img/map_0.png'
+            }, {
+               longitude: 112.276527,
+               latitude: 30.306427,
+               iconPath: '/static/img/map_2.png'
+            }]
+        }
+    },
+    methods: {
+		update(){
+			this.covers=[{
+               longitude: 112.276527,
+               latitude: 30.306427,
+               iconPath: '/static/img/map_1.png'
+            }, {
+               longitude: 112.276527,
+               latitude: 30.306427,
+               iconPath: '/static/img/map_1.png'
+            }]
 		}
-	}
-
+    }
+}

+ 9 - 11
pages/buytickets/index.vue

@@ -1,20 +1,18 @@
 <template>
 	<view>
-		
+		 <view class="page-body">
+		            <view class="page-section page-section-gap">
+		                <map style="width: 100%; height: 300px;" scale="12" :latitude="latitude" :longitude="longitude" :markers="covers">
+		                </map>
+		            </view>
+					<u-button @click="update">update</u-button>
+		        </view>
 	</view>
 </template>
 
 <script>
-	export default {
-		data() {
-			return {
-				
-			}
-		},
-		methods: {
-			
-		}
-	}
+	import api from './index.js'
+	export default api;
 </script>
 
 <style>

+ 9 - 0
pages/car/index.js

@@ -7,6 +7,15 @@
 			}
 		},
 		methods: {
+			gotoLogin(){
+				    this.$Router.push('/pages/car/login')
+
+			},
+			gotoLogin2(){
+				    uni.navigateTo({
+						url:'/pages/car/login'
+					})
+			}
 			
 		},
 		onLoad() {

+ 3 - 1
pages/car/index.vue

@@ -1,7 +1,9 @@
 <template>
 	<view>
 		aaaaaaaaa
-		<u-button>月落</u-button>
+		<u-button @click="gotoLogin">月落</u-button>
+		<u-button @click="gotoLogin2">月落</u-button>
+		
 	</view>
 </template>
 

BIN
static/img/map_0.png


BIN
static/img/map_1.png


BIN
static/img/map_2.png


+ 86 - 0
vue.config.js

@@ -0,0 +1,86 @@
+const path = require('path');
+
+const CompressionWebpackPlugin = require("compression-webpack-plugin")
+const productionGzipExtensions = ['js', 'css']
+
+function resolve(dir) {
+	return path.join(__dirname, dir)
+}
+
+let title = '';
+if (process.env.VUE_APP_NODE_NAME == 'production') {
+	title = ''
+} else if (process.env.VUE_APP_NODE_NAME == 'test') {
+	title = '(测试)'
+} else {
+	title = '(开发)'
+}
+
+const Timestamp = new Date().getTime();
+module.exports = {
+	publicPath: './',
+	outputDir: 'dist/' + process.env.NODE_ENV,
+	assetsDir: 'static',
+	lintOnSave: false,
+	devServer: {
+		host: 'localhost',
+		port: 80,
+		//解析缓存
+		disableHostCheck: true,
+		//支持gzip
+		compress: true,
+	},
+	//不输出map
+	productionSourceMap: false,
+	chainWebpack: (config) => {
+		config.entry.app = ['babel-polyfill', './src/main.js']
+		config.resolve.alias
+			.set('@', resolve('./static/'))
+
+		config.plugins.delete('preload-index');
+		config.plugins.delete('prefetch-index');
+
+		config.optimization.minimize(true);
+	},
+	configureWebpack: config => {
+		/* //开启gzip压缩,需要配置Nginx服务器gzip选项开启
+		config.plugins.push(
+			new CompressionWebpackPlugin({
+				filename: '[path].gz[query]',
+				algorithm: 'gzip',
+				test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
+				threshold: 10240,
+				minRatio: 0.8
+			})
+		); */
+
+		config.output.filename = `./static/js/[name].${Timestamp}.js`
+		config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
+
+		config.performance = {
+			hints: 'warning',
+			//入口起点的最大体积 整数类型(以字节为单位)
+			maxEntrypointSize: 50000000,
+			//生成文件的最大体积 整数类型(以字节为单位 300k)
+			maxAssetSize: 30000000,
+			//只给出 js 文件的性能提示
+			assetFilter: function(assetFilename) {
+				return assetFilename.endsWith('.js');
+			}
+		}
+	},
+	css: {
+		extract: {
+			filename: `./static/css/[name].${Timestamp}.css`,
+			chunkFilename: `./static/css/[name].${Timestamp}.css`
+		},
+		sourceMap: false,
+		loaderOptions: {
+			// 给 sass-loader 传递选项
+			sass: {
+				// @/ 是 src/ 的别名
+				// prependData: `@import "@/assets/scss/base.scss";`
+			}
+		}
+	}
+};

+ 13 - 0
yarn.lock

@@ -847,6 +847,14 @@ commondir@^1.0.1:
   resolved "https://registry.npm.taobao.org/commondir/download/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
   integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
 
+compression-webpack-plugin@^7.1.2:
+  version "7.1.2"
+  resolved "https://registry.npm.taobao.org/compression-webpack-plugin/download/compression-webpack-plugin-7.1.2.tgz?cache=0&sync_timestamp=1612085346866&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcompression-webpack-plugin%2Fdownload%2Fcompression-webpack-plugin-7.1.2.tgz#f9a1ba84d4879693e29726f6884b382940876597"
+  integrity sha1-+aG6hNSHlpPilyb2iEs4KUCHZZc=
+  dependencies:
+    schema-utils "^3.0.0"
+    serialize-javascript "^5.0.1"
+
 concat-map@0.0.1:
   version "0.0.1"
   resolved "https://registry.npm.taobao.org/concat-map/download/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -3427,6 +3435,11 @@ unbzip2-stream@^1.0.9:
     buffer "^5.2.1"
     through "^2.3.8"
 
+uni-crazy-router@0.0.31:
+  version "0.0.31"
+  resolved "https://registry.npm.taobao.org/uni-crazy-router/download/uni-crazy-router-0.0.31.tgz#14c2aa52fdef275b32504c8ba5257bf4585182e3"
+  integrity sha1-FMKqUv3vJ1syUEyLpSV79FhRguM=
+
 uni-read-pages@^1.0.5:
   version "1.0.5"
   resolved "https://registry.npm.taobao.org/uni-read-pages/download/uni-read-pages-1.0.5.tgz#452c8dcaa8977bbaef600909be926c8d9704387c"