Browse Source

新页面

lyy@qq.com 1 year ago
parent
commit
a6ead40641
8 changed files with 362 additions and 131 deletions
  1. 128 58
      main.js
  2. 1 1
      manifest.json
  3. 26 5
      package.json
  4. 19 11
      pages.json
  5. 53 9
      pages/classify/classify.vue
  6. 11 7
      pages/diningCar/diningCar.vue
  7. 72 19
      pages/diningList/diningList.vue
  8. 52 21
      pages/login/login.vue

+ 128 - 58
main.js

@@ -1,14 +1,11 @@
 import App from './App'
 
-// #ifndef VUE3
 import Vue from 'vue'
 import './uni.promisify.adaptor'
 
-import request from './utils/request.js'
-Vue.prototype.$request = request;
-
 import uView from "uview-ui";
 Vue.use(uView);
+Vue.config.productionTip = false
 
 import './css/style.css'
 
@@ -29,66 +26,139 @@ Vue.component('send-type', sendType);
 import useListTitle from './components/use-list-title/use-list-title.vue';
 Vue.component('use-list-title', useListTitle);
 
-// const autoLogin = async () => { // 小程序自动登录
-//   return new Promise(resolve => {
-// 		console.log('1111111111111111111111111111')
-//     uni.login({
-//       success: async (res) => {
-//         const result = await request('post', '/miniLogin', {
-//           code: res.code,
-// 		  appid:'000000'
-//           // appid: Vue.prototype.appId
-//         })
-//         if (result) {
-//           uni.setStorageSync("token", result.data.token);
-//           // await Vue.prototype.getUser()
-//           resolve(true)
-//         } else {
-//           uni.showModal({
-//             title: '温馨提示',
-//             content: '您尚未注册,是否前往注册?',
-//             showCancel: true,
-//             confirmText: '去注册',
-//             success: (response) => {
-//               if (response.confirm) {
-//                 // 用户点击确定
-//                 uni.navigateTo({
-//                   url: '/pages/bindPhone/bindPhone'
-//                 })
-//                 resolve(true)
-//               } else if (response.cancel) {
-//                 // 用户点击取消
-//                 resolve(false)
-//               }
-//             },
-//             fail: () => {
-//               resolve(false)
-//             }
-//           })
-//         }
-//       },
-//       fail: (e) => {
-//         resolve(false)
-//       }
-//     })
-//   })
-// }
-// autoLogin()
-Vue.config.productionTip = false
-App.mpType = 'app'
+// 配置项
+const config = process.env.ENV_PATH ? require(process.env.ENV_PATH) : require('./env/dev.js')
+Vue.prototype.serverPath = config.serverPath // 请求路径
+Vue.prototype.serverFilePath = config.serverFilePath // 文件路径
+Vue.prototype.appName = config.name // 应用名称
+Vue.prototype.appVersion = config.appVersion // 小程序版本
+Vue.prototype.webSocketURL = config.webSocketURL // socket 链接
+Vue.prototype.logo = config.logo //
+Vue.prototype.appId = config.appId // 微信小程序 appid
+Vue.prototype.$isIphoneX = false
+
+Vue.prototype.$request = function(method, url, data, isJSON, hideLoading, showErrMsg) {
+	return new Promise((resolve) => {
+		if (!hideLoading) {
+			uni.showLoading({
+				title: '请稍后...'
+			});
+		}
+
+		// 过滤 null,undefind,'' 的参数
+		for (let key in data) {
+			if (data[key] === null || data[key] === undefined || data[key] === '') {
+				delete data[key];
+			}
+		}
+
+		const token = uni.getStorageSync('token');
+		url = url.indexOf('http') === 0 ? url : `${Vue.prototype.serverPath}${url}`;
+		uni.request({
+			url,
+			method,
+			data,
+			header: {
+				"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
+				// 'Content-Type': isJSON ? '' : 'application/x-www-form-urlencoded',
+				'Authorization': `Bearer ${token}`,
+				'tenantId': Vue.prototype.tenantId
+			},
+			success: (res) => {
+				uni.hideLoading();
+				if (res.data.code === 0) {
+					resolve(res.data);
+				} else {
+					if (showErrMsg) {
+						resolve({
+							result: false,
+							msg: res.data.msg
+						});
+					} else {
+						resolve(false);
+						if (this.$refs && this.$refs.uNotify) {
+							this.$refs.uNotify.show({
+								type: 'error',
+								top: 0,
+								message: res.data.msg,
+								icon: 'error-circle'
+							});
+						}
+					}
+				}
+			},
+			fail: (err) => {
+				uni.hideLoading();
+				resolve(false);
+			}
+		});
+	});
+};
 
+Vue.prototype.autoLogin = async () => { // 小程序自动登录
+	return new Promise(resolve => {
+		uni.login({
+			success: async (res) => {
+				const result = await Vue.prototype.$request('post', '/miniLogin', {
+					code: res.code,
+					appid: '000000'
+					//appid: Vue.prototype.appId
+				})
+				if (result) {
+					uni.setStorageSync("token", result.data.access_token);
+					//await Vue.prototype.getUser()
+					resolve(true)
+				} else {
+					uni.showModal({
+						title: '温馨提示',
+						content: '您尚未注册,是否前往注册?',
+						showCancel: true,
+						confirmText: '去注册',
+						success: (response) => {
+							if (response.confirm) {
+								// 用户点击确定
+								uni.navigateTo({
+									url: '/pages/bindPhone/bindPhone'
+								})
+								resolve(true)
+							} else if (response.cancel) {
+								// 用户点击取消
+								resolve(false)
+							}
+						},
+						fail: () => {
+							resolve(false)
+						}
+					})
+				}
+			},
+			fail: (e) => {
+				resolve(false)
+			}
+		})
+	})
+}
+
+// 拼接文件完整地址
+Vue.prototype.getFilePath = (path) => {
+	return `${Vue.prototype.serverFilePath}${path}`
+}
+
+App.mpType = 'app'
 const app = new Vue({
-  ...App
+	...App
 })
 app.$mount()
-// #endif
+
 
 // #ifdef VUE3
-import { createSSRApp } from 'vue'
+import {
+	createSSRApp
+} from 'vue'
 export function createApp() {
-  const app = createSSRApp(App)
-  return {
-    app
-  }
+	const app = createSSRApp(App)
+	return {
+		app
+	}
 }
 // #endif

+ 1 - 1
manifest.json

@@ -50,7 +50,7 @@
     "quickapp" : {},
     /* 小程序特有相关 */
     "mp-weixin" : {
-        "appid" : "",
+        "appid": "wxfc1ae62fd810717d",
         "setting" : {
             "urlCheck" : false
         },

+ 26 - 5
package.json

@@ -1,6 +1,27 @@
 {
-  "dependencies": {
-    "uview-ui": "^2.0.36",
-    "vuex": "^4.0.2"
-  }
-}
+	"name": "my-project",
+	"version": "1.0.0",
+	"description": "",
+	"main": "main.js",
+	"uni-app": {
+		"scripts": {
+			"weixin:dev": {
+				"title": "开发版",
+				"env": {
+					"UNI_PLATFORM": "mp-weixin",
+					"ENV_PATH": "./env/dev.js"
+				},
+				"define": {
+					"WXCS-PLATFORM": true
+				}
+			}
+		}
+	},
+	"keywords": [],
+	"author": "",
+	"license": "ISC",
+	"dependencies": {
+		"uview-ui": "^2.0.36",
+		"vuex": "^4.0.2"
+	}
+}

+ 19 - 11
pages.json

@@ -1,10 +1,10 @@
 {
 	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
 		{
-			"path" : "pages/diningList/diningList",
+			"path" : "pages/login/login",
 			"style" : 
 			{
-				"navigationBarTitleText" : "餐车列表"
+				"navigationBarTitleText" : "登录"
 			}
 		},
 		{
@@ -16,12 +16,20 @@
 			}
 		},
 		{
-			"path" : "pages/login/login",
+			"path" : "pages/classify/detail",
 			"style" : 
 			{
-				"navigationBarTitleText" : "登录"
+				"navigationBarTitleText" : "商品详情"
 			}
 		},
+		{
+			"path" : "pages/diningList/diningList",
+			"style" : 
+			{
+				"navigationBarTitleText" : "餐车列表"
+			}
+		},
+			
 		{
 			"path" : "pages/diningCar/diningCar",
 			"style" : 
@@ -110,12 +118,12 @@
 				"selectedIconPath": "static/ic_hone.png",
 				"text": "首页"
 			},
-			{
-				"pagePath": "pages/classify/classify",
-				"iconPath": "static/ic_hone.png",
-				"selectedIconPath": "static/ic_hone.png",
-				"text": "分类"
-			},
+			// {
+			// 	"pagePath": "pages/classify/classify",
+			// 	"iconPath": "static/ic_hone.png",
+			// 	"selectedIconPath": "static/ic_hone.png",
+			// 	"text": "分类"
+			// },
 			{
 				"pagePath": "pages/user/user",
 				"iconPath": "static/ic_hone.png",
@@ -126,7 +134,7 @@
 	},
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
-		"navigationBarTitleText": "uni-app",
+		"navigationBarTitleText": "销售系统",
 		"navigationBarBackgroundColor": "#FFFFFF",
 		"backgroundColor": "#EEEEEE"
 	},

+ 53 - 9
pages/classify/classify.vue

@@ -10,7 +10,7 @@
 					</view>
 				</u-col>
 				<view class="container">
-					<u-tag text="营业中" plain shape="circle" type="success"></u-tag>
+					<u-tag plain :text="tags ? '营业中' : '离线'" :type="tags ? 'success' : 'error'" size="mini"></u-tag>
 					<view @click="btnIc">
 						<u-icon label="当前餐车名称" labelPos="left" size="16" name="arrow-down"></u-icon>
 					</view>
@@ -40,19 +40,19 @@
 			</view>
 		</u-popup> -->
 		<view class="w-full dflex-b padding-sm box-sizing-b dflex-wrap-w">
-			<view class="goods-item margin-bottom-sm" v-for="index in 4" :key="index">
-				<view class="img dflex-c">
+			<view class="goods-item margin-bottom-sm" v-for="(item, index)  in goods" :key="index">
+				<view class="img dflex-c" @click="toDetial">
 					<image mode="aspectFit" :src="'../../static/x'+ index%2 +'.jpg'"></image>
 				</view>
-				<view class="title">我是标题我是标题我是标题我是标题</view>
+				<view class="title">{{item.goods_name}}</view>
 				<view class="dflex padding-bottom-xs">
 					<u-tag plain text="销量: 199" borderColor="#FF6D20" color="#FF6D20" size="mini"></u-tag>
 				</view>
 				<view class="w-full dflex-b">
-					<view class="price">23.30</view>
+					<view class="price">{{item.goods_price}}</view>
 					<view>
 						<u-button type="primary" shape="circle" size="small" icon="map"
-							color="linear-gradient(to right, #F54319, #FF6D20)"></u-button>
+							color="linear-gradient(to right, #F54319, #FF6D20)" @click="goCart"></u-button>
 					</view>
 				</view>
 			</view>
@@ -81,18 +81,62 @@
 		data() {
 			return {
 				onIndex: 0,
-				show: false
+				show: false,
+				tags: 1,
+				goods: [ // 购物车数据列表
+					{
+						id: 1,
+						goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
+						goods_price: "520.00",
+
+					},
+					{
+						id: 2,
+						goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
+						goods_price: "520.00",
+					}, 
+					{
+						id: 3,
+						goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
+						goods_price: "520.00",
+					},
+					{
+						id: 4,
+						goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
+						goods_price: "520.00",
+					},
+					{
+						id: 5,
+						goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
+						goods_price: "520.00",
+					},
+					{
+						id: 6,
+						goods_name: "小乳酸菌牛奶酸奶饮料整箱饮品早餐酸乳益生菌",
+						goods_price: "520.00",
+					}
+				]
 			}
+		},
+		created() {
+
 		},
 		methods: {
 			// 加购
-			goCart() {},
+			goCart() {
+
+			},
 			showCart() {
 				this.$refs.cartPopup.setShow(true);
 			},
 			btnIc() {
 				uni.navigateTo({
-					url: `/pages/dingingList/dingingList`
+					url: `/pages/diningList/diningList`
+				})
+			},
+			toDetial() {
+				uni.navigateTo({
+					url: `/pages/classify/detail`
 				})
 			}
 		}

+ 11 - 7
pages/diningCar/diningCar.vue

@@ -4,12 +4,12 @@
 			<view class="box linear2" style="height:100vh;">
 				<view class="boxContent2" style="margin-top:50%;">
 					<view class="clearfix" style="margin-bottom: 10px;">
-						<text class="fz26px" style="font-weight: bold;">当前餐车名</text>
+						<text class="fz26px" style="font-weight: bold;">{{dingName}}</text>
 						<u-line dashed></u-line>
 					</view>
 					<view class="flex-container">
 						<text class="flex-item">营业状态</text>
-						<u-tag class="flex-item tag-item" plain text="营业中" size="mini"></u-tag>
+						<u-tag class="flex-item tag-item" plain :text="tags ? '营业中' : '离线'" :type="tags ? 'success' : 'error'" size="mini"></u-tag>
 					</view>
 					<text>客服电话:18011111111</text>
 				</view>
@@ -23,17 +23,18 @@
 </template>
 
 <script>
-	import request from '@/utils/request.js'
 	export default {
 		data() {
 			return {
 				img: 'https://cdn.uviewui.com/uview/album/1.jpg',
 				orderinfo: {},
-				dinList: {}
+				dinList: {},
+				tags: 1,
+				dingName: '23333'
 			}
 		},
 		created() {
-			this.fatchDing()
+			this.fatchDate()
 		},
 		methods: {
 			call() {
@@ -48,9 +49,12 @@
 					})
 				}
 			},
-			fatchDing() {
+			fatchDate() {
+				const params = {
+					id: '1111'
+				}
 				//const result = await this.$request('get', '/diningCar/{id}')
-				const result = this.$request('get', '/diningCar')
+				const result = this.$request('get', '/diningCar', params)
 				if (result) {
 					this.dinList = result.data
 				}

+ 72 - 19
pages/diningList/diningList.vue

@@ -1,18 +1,19 @@
 <template>
 	<view class="mt20px">
 		<view class="contain">
-			<view class="box" style="height: 80px;">
+			<view class="box" :class="{ 'boxed-border': showBorder }">
 				<view class="container">
 					<view class="text-container">
-						<view>当前餐车名称</view>
+						<view class="flex-item">{{dingName}}</view>
+						<u-tag plain :text="tags ? '营业中' : '离线'" :type="tags ? 'success' : 'error'" size="mini"></u-tag>
 					</view>
 					<view class="icon-container">
-						<u-icon name="plus-circle" size="24"></u-icon>
-						<u-icon name="info-circle" size="24" @click="btnIC"></u-icon>
+						<u-icon name="plus-circle" size="24" @click="call"></u-icon>
+						<u-icon style="margin-left: 10px;" name="info-circle" size="24" @click="btnIC"></u-icon>
 					</view>
 				</view>
-				<view style="width: 50px;">
-					<u-tag plain text="营业中" type="success" size="mini"></u-tag>
+				<view :class="{ 'btnbor': showBorder }" v-if="showBorder">
+					<u-tag text="镂空" bgColor='#FF6D20' borderColor='#FF6D20' icon="map"></u-tag>
 				</view>
 			</view>
 		</view>
@@ -23,14 +24,41 @@
 	export default {
 		data() {
 			return {
-
+				tags: 1,
+				showBorder: false,
+				dingName: '23333',
+				orderinfo: {},
+				tableData: []
 			}
 		},
+		created() {
+			this.fatchDate()
+		},
 		methods: {
+			call() {
+				if (this.orderinfo.shopCall) {
+					uni.makePhoneCall({
+						phoneNumber: this.orderinfo.shopCall
+					});
+				} else {
+					uni.showToast({
+						icon: 'none',
+						title: '暂无商家电话'
+					})
+				}
+			},
 			btnIC() {
 				uni.navigateTo({
 					url: `/pages/diningCar/diningCar`
 				})
+			},
+			fatchDate() {
+				//const result = await this.$request('get', '/diningCar/{id}')
+				const result = this.$request('get', '/diningCar/queryDiningCar')
+				if (result) {
+					console.log('result', result.data)
+					this.tableData = result.data
+				}
 			}
 		}
 	}
@@ -39,7 +67,7 @@
 <style scoped lang="scss">
 	.box {
 		padding: 20rpx 20rpx 0;
-		// background-image: linear-gradient(#00a551 10%, #fff 30%);
+		height: 80px;
 		border-bottom-left-radius: 30rpx;
 		border-bottom-right-radius: 30rpx;
 		background-position: top;
@@ -47,14 +75,32 @@
 		background-repeat: no-repeat;
 		border-radius: 20rpx;
 		background-color: #fff;
+
+
+	}
+
+	.boxed-border {
+		border: 1px solid #FF6D20;
+		/* 边框样式 */
+		padding: 20rpx 20rpx 0;
+		border-radius: 20rpx;
+		/* 添加圆角 */
+
+		.btnbor {
+			margin-right: -11px;
+			margin-top: -3px;
+			float: right;
+		}
 	}
 
 	.box:hover {
-	  border: 1px solid #2979ff; /* 鼠标悬停时显示边框 */
+		border: 1px solid #FF6D20;
+		/* 鼠标悬停时显示边框 */
 	}
-	
+
 	.box:active {
-	  border: 1px solid #0056b3; /* 鼠标按下时显示另一种边框颜色 */
+		border: 1px solid #F54319;
+		/* 鼠标按下时显示另一种边框颜色 */
 	}
 
 	.container {
@@ -65,8 +111,19 @@
 	}
 
 	.text-container {
-		flex: 1;
-		/* 文本占满剩余空间 */
+		display: flex;
+		flex-direction: column;
+		align-items: flex-start;
+		/* 左对齐 */
+	}
+
+	.flex-item {
+		margin-bottom: 10px; 
+	}
+
+	.tag-item {
+		margin-left: auto;
+		/* 将标签推到右边 */
 	}
 
 	.icon-container {
@@ -76,11 +133,7 @@
 		/* 水平排列子元素 */
 		justify-content: flex-end;
 		/* 子元素右对齐 */
-
-	}
-
-	.icon-container u-icon {
-		margin-right: 15px;
-		/* 设置图标之间的间距 */
+		margin-top: -30px;
+		gap: 10px; /* 设置图标之间的距离 */
 	}
 </style>

+ 52 - 21
pages/login/login.vue

@@ -6,6 +6,7 @@
 
 <script>
 	export default {
+		name: 'MyLogin',
 		data() {
 			return {
 				infoData: {}
@@ -13,35 +14,65 @@
 		},
 		methods: {
 			loginUse() {
-				let that = this;
 				wx.login({
-					success: function(e) {
+					success: async (e) => {
 						console.log('数据:', e)
-
-						uni.request({
-							url: 'http://36.137.224.81:8030/auth/miniLogin?tenantId=000000&code=' + e
-								.code,
-							header: {
-								"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", //
-								// "Content-Type": "application/json;charset=UTF-8", //
-							},
-							method: 'post',
-							success: res => {
-								console.log('登录成功:', res)
+						const result = await this.$request('post', '/miniLogin?tenantId=000000&code=' + e.code)
+						console.log('登录成功:', result)
+						// 处理响应数据
+						if (!result) {
+							console.log('登录成功:', result.data)
+							var token = result.data.access_token;
+							var haveOpenid = result.data.open_id;
+							uni.setStorageSync("token", token);
+							success: (result) => {
+								console.log('登录成功:', result)
 								uni.hideLoading()
-								if (res.data.code == 200) {
-									that.infoData = res.data.data
-								}
-
-							},
-							fail: err => {
+								uni.navigateTo({
+									url: `/pages/classify/classify`
+								})
+							};
+							fail: (result) => {
 								uni.hideLoading()
 							}
-						})
+						}
 					}
 				})
-			}
+				
+				// let that = this;
+				// wx.login({
+				// 	success: function(e) {
+				// 		console.log('数据:', e)
 
+				// 		uni.request({
+				// 			url: 'http://36.137.224.81:8030/auth/miniLogin?tenantId=000000&code=' + e
+				// 				.code,
+				// 			header: {
+				// 				"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", //
+				// 				// "Content-Type": "application/json;charset=UTF-8", //
+				// 			},
+				// 			method: 'post',
+				// 			success: res => {
+				// 				console.log('登录成功:', res)
+				// 				uni.hideLoading()
+				// 				var token = res.data.data.access_token;
+				// 				console.log('token:', token)
+				// 				uni.setStorageSync("token", token);
+				// 				uni.navigateTo({
+				// 					url: `/pages/classify/classify`
+				// 				})
+				// 				// if (res.data.code == 200) {
+				// 				// 	that.infoData = res.data.data
+				// 				// }
+				// 			},
+				// 			fail: err => {
+				// 				uni.hideLoading()
+				// 			}
+				// 		})
+				// 	}
+				// })
+				
+			}
 		}
 	}
 </script>