62 对接支付宝沙箱

接下来我们提交订单,此时就会进入到支付宝支付页面,我们的项目采用支付宝支付,对接支付宝沙箱,和我们在公司的做法是差不多的流程,只不过这是一个测试版,个人也可以去做,为什么市面上很少有这样的视频,因为他的API本身就有问题,所以大家在这里一定要好好听。
首先,我们去点击 '支付宝支付' ,然后再点击 '提交订单' ,此时前端要做什么事情,提交订单以后,我们要去看你有没有选择收货地址,并且点击发送请求,修改你的订单状态以及将购物车数据删除掉,如果所删除完事以后,我们已经做好了,这里会返回一个true,我们还要在发送一个请求,
支付的时候,你具体要做什么,并且总金额也是一定要传的,我们去拿到支付需要的信息
复制代码
// 商品名称是一个数组,需要遍历
let newArr = [];
this.goodsList.forEach(v => {
    // push成一个新的数组
    newArr.push(v.goods_name);
})

// 支付传递的参数 拿到支付信息
let dataOrder = {
    // 订单号
    orderId: this.order_id,

    // 商品名称 是一个数组
    // name: this.goodsList.goods_name,
    name: newArr.join(''),

    // 支付总金额
    price: this.total.price
}
前端给后端传什么呢? 我们要传的是订单的详情
复制代码
1, 订单号,
一定要传,你如果支付成功了,他的状态可能会修改 从 '2' 改为 '3'

2, 你支付的时候,
还有显示你买是什么商品,这个也要传过去

3,并且 总金额也是一定要传的
当我们 点击 '提交订单' ,他是不是跳转到支付宝支付页面
复制代码
// 提交订单   这是前端要做的事情
goPayment() {
    // 判断是否选择了收货地址
    if (!this.path) return Toast('请填写收货地址');

    // 发送请求=> 1,修改订单状态 2,删除购物车的数据
    http.$axios({
        url: '/api/submitOrder',
        method: 'post',
        headers: { // 哪个用户新增地址
            token: true
            // 一般支付都要写 提交订单部需要
            // 'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
            // 前端给后端传递的订单号
            orderId: this.order_id,
            // 购物车里面选中的数据
            shopArr: this.selectList
        }
    }).then(res => {
        // 商品名称是一个数组,需要遍历
        let newArr = [];
        this.goodsList.forEach(v => {
            // push成一个新的数组
            newArr.push(v.goods_name);
        })

        // 支付传递的参数 拿到支付信息
        let dataOrder = {
            // 订单号
            orderId: this.order_id,

            // 商品名称 是一个数组
            // name: this.goodsList.goods_name,
            name: newArr.join(''),

            // 支付总金额
            price: this.total.price
        }

        // 返回true,此时我们还要在发送一个请求
        if (res.success) {
            // 去支付 请求
            http.$axios({
                url: '/api/payment',
                method: 'post',
                headers: { // 哪个用户新增地址
                    token: true,
                    // 一般支付都要写 提交订单部需要
                    'content-type': 'application/x-www-form-urlencoded'
                },
                // qs是为了增加安全性
                data: qs.stringify(dataOrder);
            }).then(res => {
                console.log(res),
            })
        }
    })
}
Content-Type: application/x-www-form-urlencoded 就是表示前端向后端提交的是表单(form)数据的形式。
✅ 精确解释:
这个 Content-Type 是 HTML 表单(form)默认的提交编码方式,它的名字就可以拆解理解: 部分 含义 application/ 数据类型是应用级数据 x-www-form-urlencoded "x"表示自定义,"www"表示万维网,"form"表示表单,"urlencoded"表示URL编码
👉 合起来就是:
"这是一个用于 Web 表单提交的数据,并且字段被 URL 编码了"

Vue: qs的使用方法

1, 安装qs
复制代码
npm install qs -S
2, 引入
复制代码
import qs from 'qs'
3, 项目中去使用qs
复制代码
// qs是为了增加安全性
data: qs.stringify(dataOrder);
一, 提交订单前端要做的事情 完整代码
复制代码
// 提交订单
goPayment() {
    // 判断是否选择了收货地址
    if (!this.path) return Toast('请填写收货地址');

    // 发送请求=> 1,修改订单状态 2,删除购物车的数据
    http.$axios({
        url: '/api/submitOrder',
        method: 'post',
        headers: { // 哪个用户新增地址
            token: true
            // 一般支付都要写 提交订单部需要
            // 'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
            // 前端给后端传递的订单号
            orderId: this.order_id,
            // 购物车里面选中的数据
            shopArr: this.selectList
        }
    }).then(res => {
        // 商品名称是一个数组,需要遍历
        let newArr = [];
        this.goodsList.forEach(v => {
            // push成一个新的数组
            newArr.push(v.goods_name);
        })

        // 支付传递的参数 拿到支付信息
        let dataOrder = {
            // 订单号
            orderId: this.order_id,

            // 商品名称 是一个数组
            // name: this.goodsList.goods_name,
            name: newArr.join(''),

            // 支付总金额
            price: this.total.price
        }

        // 返回true,此时我们还要在发送一个请求
        if (res.success) {
            // 去支付 请求
            http.$axios({
                url: '/api/payment',
                method: 'post',
                headers: { // 哪个用户新增地址
                    token: true,
                    // 一般支付都要写 提交订单部需要
                    'content-type': 'application/x-www-form-urlencoded'
                },
                // qs是为了增加安全性
                data: qs.stringify(dataOrder);
            }).then(res => {
                console.log(res);
            })
        }
    })
}
二, 提交订单后端要做的事情 完整代码 需要写两个接口
注意:对接支付一定是后端做的

第一步对接沙箱地址

复制代码
沙箱地址
https://open.alipay.com/develop/sandbox/account

沙箱账号
https://open.alipay.com/develop/sandbox/account

https://github.com/npm/cli/releases/tag/v11.6.2

nodejs的alipay-sdk
https://www.npmjs.com/package/alipay-sdk


支付宝新版App支付nodejs版sdk. 
https://github.com/fym201/alipay-node-sdk

支付宝开放平台 Alipay SDK for Node.js 
https://github.com/alipay/alipay-sdk-nodejs-all

蚂蚁金服开放平台 node-sdk
https://www.yuque.com/chenqiu/alipay-node-sdk/config-sdk#


支付宝,文档中心,网页和移动应用
https://opendocs.alipay.com/open/54/103419/

创建 server/db/alipay.js 文件

复制代码
// 引入 sdk
const AlipaySdk = require('alipay-sdk').default;
const alipaySdk = new AlipaySdk({
	// AppId
	appId: '',
	// 签名算法
	signType: 'RSA2',
	// 支付宝网关
	gateway: '',
	// 支付宝公钥
	alipayPublicKey: '',
	// 应用私钥
	privateKey: ''
});

module.export = alipaySdk;
自己的 创建 server/db/alipay.js 文件
复制代码
// 引入AlipaySdk
const AlipaySdk = require('alipay-sdk').default;

const alipaySdk = new AlipaySdk({
	// AppId
	appId: '9021000157628688',

	// 签名算法
	signType: 'RSA2',

	// 支付宝网关
	gateway: 'https://openapi-sandbox.dl.alipaydev.com/gateway.do',

	// 支付宝公钥
	alipayPublicKey: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgv5FNgK76pHRR/QAir5dKJ3xzQfy+1eTMhmmaN9BoaCVeD37OAskPi4JCbrOesCkE2iVfvJkQtnVwI4KNPM+ZWwRBIPWX4kB4qLHjaOtX04CYD5JWpql58e3UNsof16p5KvMFRq6NpqDldDZDp1eGLzoqqKxW+lzSn+OM5w2yEVlxgOYi34Jm/Ru5DOAch1ceJQ/NB9jRzPdwSEk6/PG5Cz+0X+yOfaTIp8xwTC2yKe0+gE9t4vqxNw0XianQlDuNqgUq86ypAVTn7mOBdc54sp417QYSV+ERs0wQ7Ixwf/iOHpUZ43mVf0+klRyHujTUZfIwgYHj1bV6/GFVhX8HQIDAQAB',

	// 应用私钥
	privateKey: 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCKRysgfCLo0ATeay15Wk/TSYhAlGYpoAgz+JxMPM9pQElnuxHaGwHNcwyvRhumYG/4zwQzaN6PlNGoX8e5dIxf+WrM5b/fEaGP3iDiHGfnxcpIf16VCOM1Ca82O4w4fSHTTmNir8qcgnPHs36RgXv9+nAATQSXL3HZaMrDzLPcAoMdNHjhna9pm5avn6BLv8UIJ4juaaQS1jKwPLvtb5NUee//+WehLnBkC0dNmRVqkeZsZJiNIEfmOkVIGmhMp8GPUjcxy3TkCxjrRb+DMB83NVJY4drleGmDBhbl2LAGEqrGo3GfVAuLrtwijO1las5Ox9M3ciBwCIVGzTmdIj91AgMBAAECggEANKhHbxZ2wMu+nuiXp5fRwDdHULhyczWDCi+JbarWnVEi4wKlGLaiKBfA49pB20jsOwaypdUws+LLOGBJEYGll0LG/gIb4Bm5uaywPwrsMqHql1MRtJVu2Jq4g2GH01crk2lNhZ5F/PXcm1bqQwTZL+23yxWJQv2JUG6MkKWadJRXrh9PJ5DQGalFAGaOP1U04gZrjKnXd+U3Mg/JBc/Im3z5hj64/tSHd4rASTRvtCuSDmkainPHuwuYV0IhQI7rJSHSEn9mFZ9j0GOrzvCHuR4rXt6DpZmBL4XWK6bNXggW1sDtLe7gp74xMPRHULJHfZwPTL6BnLH35Dn5OPgI3QKBgQD3DqHKDNo5gmuM6cqYMz4RRcqlVtJrh7kph7uqqCRjClIc2LEKd4/u4OFKg7jrXYYt8hq75d1fpOvbQwEZf2UEHamd1ZcQ/NGb+S2BvedRFUJUZ4k7CovC14XYgAVAXDh1UGI8uET8KjAforsjHOZrXegnTqU1pnLcKXBM0oCBUwKBgQCPSIddrIXrCl4ZNCMbLRQt2oQ4oI1HpTZMppIgA9oYBG2rQlw9oppJdsAB2zbCne6jS7zZwUgdwsEhtH1N6Z8P1TWZOTtEZDrGq2zAgh/HMRnP5/OM8vy/XBtH6W6IFBDKhHGFVY23JgM25vnNbsBkS8q0sSJcEh7m37yIJ4W7FwKBgC98w4JnyAZn2C5kvclViCefx5zSPG3oz6F48oyR9zSGRlQ/HoCJjMP4u7Ur7n5nIqRwNc1KGKwKsj8Z+PsirpME9JZe+MOOJOgbFDEtBGpkcLRylkEf/M89x/9eVCQT1dJO2iMbtD7YCRn7mIbeRjf6++WaS00tqkRBPtG1YHf7AoGAS4KjpCBJqyaZlJq/bZECM3AXgmhKTFmrFhYqqCifhUzAJyMfzXOl79VfNxs57rKgkvpVGkUcJmL+uS6PYsIeC5AHYSqiK1bPCuhIteNdr/IWclUBK2TbAlYeInXIxHoepzvJP8Vom/6ybvqm5zbYuYKf3z4Cp5b9Jhr/FpoNhh0CgYEAqEYVm0TvQura3yDD+veVI+kRzyKuPS5kS0FrPnNx1IOgvGuGDKl0WJZsu3FYIFtwuQZuxBmMciSRoYSwV0eT4QGv12zisKpm2YAcOmQAbNMlMg7he4U1ugYI2njTlvsrM6KhJcY5DgHo3zxCbQIsckHOsjE/k5c3zaRGH1999bw='
});

module.exports = alipaySdk;
回到 server/routes/index.js 编写 发起支付接口
复制代码
1, 引入支付宝配置文件
const alipaySdk = require('../db/alipay.js');
const AlipayFormData = require('alipay-sdk/lib/form').default;

2, 编写接口
// 发起支付 接口(后端)
router.post('/api/submitOrder', function(req, res, next) {
	// 以下几个参数是前端给后端传的数据
	// 订单号
	let orderId = req.body.orderId;

	// 商品总价
	let price = req.body.price;

	// 购买商品的名称
	let name = req.body.name;

	// 开始对接支付宝API(SDK)
	const formData = new AlipayFormData();

	// 调用 setMethod 并传入 get,会返回可以跳转到支付页面的 url
	formData.setMethod('get');

	// 支付时信息
	// get method 需要确保 field 都是字符串
	// 老师的
	formData.addField('bizContent', {
		// 订单号
		outTradeNo: 'orderId',
		// 写死的
		productCode: 'FAST_INSTANT_TRADE_PAY',
		// 商品总价格 
		totalAmount: price,
		// 商品名称
		subject: name
	});


	// 自己的
	// formData.addField('bizContent', JSON.stringify({
	// 	// 订单号
	// 	outTradeNo: 'orderId',
	// 	// 写死的
	// 	productCode: 'FAST_INSTANT_TRADE_PAY',
	// 	// 商品总价格 
	// 	totalAmount: price,
	// 	// 商品名称
	// 	subject: name
	// }));

	// 支付成功或者失败跳转链接
	formData.addField('returnUrl', 'http://localhost:8080/payment');

	// 返回 promise
	const result = await alipaySdk.exec(
		'alipay.trade.page.pay', {}, {
			formData: formData
		},
	);
	// 对接支付宝成功,支付宝方返回的数据
	result.then(resp => {
		res.send({
			data: {
				code: 200,
				success: true,
				msg: '支付中',
				paymentUrl: resp
			}
		})
	})
})
蚂蚁金服开放平台 node sdk 官方文档
复制代码
https://www.yuque.com/chenqiu/alipay-node-sdk/page_api#

https://opendocs.alipay.com/open/54/103419/
创建src/views/Payment.vue一个支付宝支付了跳转页面
复制代码
<template>
	<div>
		支付了
	</div>
</template>

<script>
</script>

<style>
</style>
配置路由 在 src/router/index.js 文件添加如下内容,看到'支付了'表示路由配置成功:
复制代码
{
    path: "/payment",
    name: "Payment",
    component: () =>
        import("../views/Payment.vue"),
}
对接支付宝沙箱 实现代码
复制代码
1, src/views/Order.vue
<template>
	<div class="order container">
		<header>
			<i class="iconfont icon-a-huaban1fuben44" @click="$router.back()"></i>
			<span>提交订单</span>
			<i class="iconfont icon-kefu"></i>
		</header>
		<section>
			<div class="path">
				<h3 class="path-title">收货信息:</h3>
				<!-- {{path}} -->
				<div class="path-content" @click="goPath">
					<div>
						<span>{{path.name}}</span>
						<span>{{path.tel}}</span>
						<!-- <span>张三</span>
						<span>18017927192</span> -->
					</div>
					<div>
						<span>{{path.province}}</span>
						<span>{{path.city}}</span>
						<span>{{path.county}}</span>
						<span>{{path.addressDetail}}</span>
						<!-- <span>省</span>
						<span>市</span>
						<span>区县</span>
						<span>详细地址</span> -->
					</div>
				</div>
			</div>
			<div class="payment">
				<!-- {{radioPayment}} -->
				<div class="payment-title">支付方式:</div>
				<van-radio-group v-model="radioPayment">
					<van-radio name="wx">微信支付</van-radio>
					<van-radio name="ali">支付宝支付</van-radio>
				</van-radio-group>
			</div>
			<div class="goods">
				<!-- {{goodsList}} -->
				<ul>
					<li v-for="(item,index) in goodsList" :key="index">
						<div>
							<img :src="item.goods_imgUrl" alt="" />
						</div>
						<div class="goods-content">
							<h4>{{item.goods_name}}</h4>
							<div>规格: 暂无</div>
							<div class="goods-total">
								<span class="goods-price">¥{{item.goods_price}}</span>
								<span>x{{item.goods_num}}</span>
							</div>
						</div>
					</li>
				</ul>
			</div>
		</section>
		<footer>
			<div class="order-total">
				<span>共</span>
				<b>{{total.num}}</b>
				<span>件,</span>
				<span>总金额:</span>
				<em>¥{{total.price}}</em>
			</div>
			<div class="order-topay" @click="goPayment">
				提交订单
			</div>
		</footer>
	</div>
</template>

<script>
	import http from '@/common/api/request.js'
	import {
		mapState,
		mapGetters,
		mapMutations
	} from 'vuex';
	import {
		Toast
	} from 'vant';
	import bus from '@/common/bus.js'
	import qs from 'qs'
	export default {
		data() {
			return {
				radioPayment: 'wx',
				path: {},
				item: [],
				total: {
					price: 0,
					num: 0
				}
			}
		},
		computed: {
			...mapState({
				// list: state => state.cart.list
				// list: state => state.order.list
				order_id: state => state.order.order_id,
				selectList: state => state.cart.selectList
			}),
			...mapGetters(['defaultPath'])
			// ...mapGetters(['total', 'defaultPath']),
			// console.log(this.list); // 空值
		},
		created() {
			this.goodsList = JSON.parse(this.$route.query.goodsList);

			// 调用 查询地址
			this.selectAddress();

			// 查询订单号
			// console.log(this.order_id);

			// 读取存储值->订单号  20210709145102260155
			// console.log(localStorage.getItem('tea_orderId'));

			// Cart.vue 传值到这里 打印一下
			// console.log(this.$route.query.detail);		
		},
		// 使用了 keep-Alive时出现的生命周期函数 activated() {}
		activated() {
			// 接收 src/views/path/Path-Index.vue 传值
			bus.$on('selectPath', function(data) {
				this.path = JSON.parse(data);

				// console.log(this.path, "xxx");
				// console.log(JSON.parse(data), "data");
			}.bind(this));
			// console.log(this.path, "yyy");


			// 查询到地址了
			// 选中的商品的id号  转换  接收也要显式
			this.item = JSON.parse(this.$route.query.detail); // 显式
			// this.item = JSON.parse(this.$route.params.detail); // 隐式

			// 接收从 Cart.vue 文件中传递的 goodsList
			this.goodsList = JSON.parse(this.$route.query.goodsList);


			// 调用 查询订单
			this.selectOrder();
		},
		methods: {
			...mapMutations(['initData', 'initOrder']),

			// 查询地址 封装
			selectAddress() {


				// 请求收货地址
				http.$axios({
					url: '/api/selectAddress',
					method: 'post',
					headers: { // 哪个用户新增地址
						token: true
					}
				}).then(res => {
					// 将数据存储到 vuex 中
					this.initData(res.data);

					// 有默认收货地址
					if (this.defaultPath.length) {
						this.path = this.defaultPath[0];
					} else {
						this.path = res.data[0];
					}
				});
			},

			// 查询订单 封装
			selectOrder() {
				// 查询订单(前端)
				http.$axios({
					url: '/api/selectOrder',
					method: 'post',
					headers: { // 哪个用户新增地址
						token: true
					},
					data: {
						// 前端给后端传递的订单号
						orderId: this.order_id
					}
				}).then(res => {
					// 将数据存储到 vuex 中
					this.initOrder(res.data);

					this.total = {
						price: res.data[0].goods_price,
						num: res.data[0].goods_num
					}
				});
			},


			// 选择收货地址
			goPath() {
				this.$router.push({
					path: '/path',
					query: {
						type: 'select'
					}
				});
			},

			// 提交订单
			goPayment() {
				// 判断是否选择了收货地址
				if (!this.path) return Toast('请填写收货地址');

				// 发送请求=> 1,修改订单状态 2,删除购物车的数据
				http.$axios({
					url: '/api/submitOrder',
					method: 'post',
					headers: { // 哪个用户新增地址
						token: true
						// 一般支付都要写 提交订单部需要
						// 'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						// 前端给后端传递的订单号
						orderId: this.order_id,
						// 购物车里面选中的数据
						shopArr: this.selectList
					}
				}).then(res => {
					// 商品名称是一个数组,需要遍历
					let newArr = [];
					this.goodsList.forEach(v => {
						// push成一个新的数组
						newArr.push(v.goods_name);
					})

					// 支付传递的参数 拿到支付信息
					let dataOrder = {
						// 订单号
						orderId: this.order_id,

						// 商品名称 是一个数组
						// name: this.goodsList.goods_name,
						name: newArr.join(''),

						// 支付总金额
						price: this.total.price
					}

					// 返回true,此时我们还要在发送一个请求
					if (res.success) {
						// 去支付 请求
						http.$axios({
							url: '/api/payment',
							method: 'post',
							headers: { // 哪个用户新增地址
								token: true,
								// 一般支付都要写 提交订单部需要
								'content-type': 'application/x-www-form-urlencoded'
							},
							// qs是为了增加安全性
							data: qs.stringify(dataOrder)
						}).then(res => {
							// 打开支付宝支付链接
							if (res.success) {
								// 打开支付宝页面
								window.location.href = res.paymentUrl;
							}

							// window.open(res);
							// console.log(res);
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		height: 44px;
		color: #fff;
		background-color: #b0352f;



		i {
			padding: 0 18px;
			font-size: 24px;
		}

		span {
			font-size: 18px;
			font-weight: 300;
		}
	}

	section {
		background-color: #f7f7f7;

		.path-title {
			padding: 6px 15px;
			font-size: 20px;
			// color: dimgray;
		}

		.path-content {
			padding: 6px 15px;
			font-size: 18px;
			background-color: #FFFFFF;

			span {
				padding-right: 6px;
			}
		}

		.payment {
			padding: 6px 15px;
			margin-top: 15px;
			font-size: 16px;
			background-color: #FFFFFF;

			.van-radio-group {
				display: flex;
				padding: 10px 0;

				.van-radio {
					padding-right: 10px;
				}
			}
		}

		.goods {
			padding: 6px 15px;
			margin-top: 15px;
			font-size: 16px;
			background-color: #FFFFFF;

			ul {
				width: 100%;

				li {
					display: flex;
					width: 100%;

					img {
						width: 74px;
						height: 74px;
					}

					.goods-content {
						display: flex;
						flex: 1;
						flex-direction: column;
						justify-content: space-between;
						padding-left: 15px;

						.goods-total {
							display: flex;
							justify-content: space-between;

							.goods-price {
								font-size: 18px;
								color: #b0352f;
							}
						}
					}
				}
			}
		}
	}

	footer {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		line-height: 50px;
		border-top: 1px solid #CCC;

		.order-total {
			font-size: 20px;

			span {
				padding: 0 6px;
			}

			b {
				color: #b0352f;
			}

			em {
				font-size: 22px;
				color: #b0352f;
			}
		}



		.order-topay {
			width: 120px;
			line-height: 50px;
			text-align: center;
			color: #fff;
			background-color: #b0352f;
			font-size: 18px;
		}

	}
</style>





2, src/views/Payment.vue
<template>
	<div>
		支付了
	</div>
</template>

<script>
</script>

<style>
</style>






3, src/router/index.js
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [{
		path: "/home",
		name: "Home",
		component: Home,
	},
	{
		path: "/",
		redirect: "/home", // 重定向
	}, {
		path: "/list",
		name: "List",
		component: () =>
			import("../views/List.vue"),
	}, {
		path: "/cart",
		name: "Cart",
		meta: {
			keepAlive: true, // 此组件需要被缓存
		},
		component: () =>
			import("../views/Cart.vue"),
	}, {
		path: "/my",
		name: "My",
		component: () =>
			import("../views/My.vue"),
	},
	{
		path: "/search",
		children: [{
			path: "/",
			name: "index",
			component: () =>
				import("../views/search/Search-index.vue"),
		}, {
			path: "/search/list",
			name: "Search-list",
			component: () =>
				import("../views/search/Search-list.vue"),
		}],
		component: () =>
			import("../views/Search.vue"),
	},
	{
		path: "/detail",
		name: "Detail",
		meta: {
			keepAlive: true, // 此组件需要被缓存
		},
		component: () =>
			import("../views/Detail.vue"),
	},
	{
		path: "/login",
		name: "Login",
		component: () =>
			import("../views/login/Login.vue"),
	},
	{
		path: "/userLogin",
		name: "UserLogin",
		component: () =>
			import("../views/login/UserLogin.vue"),
	},
	{
		path: "/register",
		name: "Register",
		component: () =>
			import("../views/login/Register.vue"),
	},
	{
		path: "/recovery",
		children: [{
			path: "/",
			name: "RecoveryIndex",
			component: () =>
				import("../views/recovery/RecoveryIndex.vue"),
		}, {
			path: "/recovery/btn",
			name: "RecoveryBtn",
			component: () =>
				import("../views/recovery/RecoveryBtn.vue"),
		}],
		component: () =>
			import("../views/recovery/Recovery.vue"),
	},
	{
		path: "/path",
		children: [{
			path: "/",
			name: "Path-Index",
			component: () =>
				import("../views/path/Path-Index.vue"),
		}, {
			path: "/path/path-list",
			name: "Path-List",
			component: () =>
				import("../views/path/Path-List.vue"),
		}, {
			path: "/path/path-province-city",
			name: "Path-Province-City",
			component: () =>
				import("../views/path/Path-Province-City_bak.vue"),
		}, {
			path: "/path/path-address",
			name: "Path-Address",
			component: () =>
				import("../views/path/Path-Address_bak.vue"),
		}],
		component: () =>
			import("../views/Path.vue"),
	},
	{
		path: "/order",
		name: "Order",
		meta: {
			keepAlive: true, // 此组件需要被缓存
		},
		component: () =>
			import("../views/Order.vue"),
	},
	{
		path: "/payment",
		name: "Payment",
		component: () =>
			import("../views/Payment.vue"),
	}
];

const router = new VueRouter({
	mode: "history",
	base: process.env.BASE_URL,
	routes,
});

export default router;






4, server/db/alipay.js
// 引入AlipaySdk
const AlipaySdk = require('alipay-sdk').default;


// 实例化客户端 官方提供的
// const alipaySdk = new AlipaySdk({
// 	// 设置应用 ID
// 	appId: '9021000157627689',
// 	// 设置应用私钥
// 	privateKey: 9021000157627689,
// 	// 设置支付宝公钥
// 	alipayPublicKey: fs.readFileSync('/path/to/alipay-public-key.pem', 'ascii'),
// 	// 密钥类型,请与生成的密钥格式保持一致,参考平台配置一节
// 	// keyType: 'PKCS1',
// 	// 设置网关地址,默认是 https://openapi.alipay.com
// 	// endpoint: 'https://openapi.alipay.com',
// });

const alipaySdk = new AlipaySdk({
	// AppId
	appId: '9021000157627689',

	// 签名算法
	signType: 'RSA2',

	// 支付宝网关
	gateway: 'https://openapi-sandbox.dl.alipaydev.com/gateway.do',

	// 支付宝公钥
	alipayPublicKey: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgv5FNgK76pHRR/QAir5dKJ3xzQfy+1eTMhmmaN9BoaCVeD37OAskPi4JCbrOesCkE2iVfvJkQtnVwI4KNPM+ZWwRBIPWX4kB4qLHjaOtX04CYD5JWpql58e3UNsof16p5KvMFRq6NpqDldDZDp1eGLzoqqKxW+lzSn+OM5w2yEVlxgOYi34Jm/Ru5DOAch1ceJQ/NB9jRzPdwSEk6/PG5Cz+0X+yOfaTIp8xwTC2yKe0+gE9t4vqxNw0XianQlDuNqgUq86ypAVTn7mOBdc54sp417QYSV+ERs0wQ7Ixwf/iOHpUZ43mVf0+klRyHujTUZfIwgYHj1bV5/GFVhX8HQIDAQAB',

	// 应用私钥
	privateKey: 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCKRysgfCLo0ATeay15Wk/TSYhAlGYpoAgz+JxMPM9pQElnuxHaGwHNcwyvRhumYG/4zwQzaN6PlNGoX8e5dIxf+WrM5b/fEaGP3iDiHGfnxcpIf16VCOM1Ca82O4w4fSHTTmNir8qcgnPHs36RgXv9+nAATQSXL3HZaMrDzLPcAoMdNHjhna9pm5avn6BLv8UIJ4juaaQS1jKwPLvtb5NUee//+WehLnBkC0dNmRVqkeZsZJiNIEfmOkVIGmhMp8GPUjcxy3TkCxjrRb+DMB83NVJY4drleGmDBhbl2LAGEqrGo3GfVAuLrtwijO1las5Ox9M3ciBwCIVGzTmdIj91AgMBAAECggEANKhHbxZ2wMu+nuiXp5fRwDdHULhyczWDCi+JbarWnVEi4wKlGLaiKBfA49pB20jsOwaypdUws+LLOGBJEYGll0LG/gIb4Bm5uaywPwrsMqHql1MRtJVu2Jq4g2GH01crk2lNhZ5F/PXcm1bqQwTZL+23yxWJQv2JUG6MkKWadJRXrh9PJ5DQGalFAGaOP1U04gZrjKnXd+U3Mg/JBc/Im3z5hj64/tSHd4rASTRvtCuSDmkainPHuwuYV0IhQI7rJSHSEn9mFZ9j0GOrzvCHuR4rXt6DpZmBL4XWK6bNXggW1sDtLe7gp74xMPRHULJHfZwPTL6BnLH35Dn5OPgI3QKBgQD3DqHKDNo5gmuM6cqYMz4RRcqlVtJrh7kph7uqqCRjClIc2LEKd4/u4OFKg7jrXYYt8hq75d1fpOvbQwEZf2UEHamd1ZcQ/NGb+S2BvedRFUJUZ4k7CovC14XYgAVAXDh1UGI8uET8KjAforsjHOZrXegnTqU1pnLcKXBM0oCBUwKBgQCPSIddrIXrCl4ZNCMbLRQt2oQ4oI1HpTZMppIgA9oYBG2rQlw9oppJdsAB2zbCne6jS7zZwUgdwsEhtH1N6Z8P1TWZOTtEZDrGq2zAgh/HMRnP5/OM8vy/XBtH6W6IFBDKhHGFVY23JgM25vnNbsBkS8q0sSJcEh7m37yIJ4W7FwKBgC98w4JnyAZn2C5kvclViCefx5zSPG3oz6F48oyR9zSGRlQ/HoCJjMP4u7Ur7n5nIqRwNc1KGKwKsj8Z+PsirpME9JZe+MOOJOgbFDEtBGpkcLRylkEf/M89x/9eVCQT1dJO2iMbtD7YCRn7mIbeRjf6++WaS00tqkRBPtG1YHf7AoGAS4KjpCBJqyaZlJq/bZECM3AXgmhKTFmrFhYqqCifhUzAJyMfzXOl79VfNxs57rKgkvpVGkUcJmL+uS6PYsIeC5AHYSqiK1bPCuhIteNdr/IWclUBK2TbAlYeInXIxHoepzvJP8Vom/6ybvqm5zbYuYKf3z4Cp5b9Jhr/FpoNhh0CgYEAqEYVm0TvQura3yDD+veVI+kRzyKuPS5kS0FrPnNx1IOgvGuGDKl0WJZsu3FYIFtwuQZuxBmMciSRoYSwV0eT4QGv12zisKpm2YAcOmQAbNMlMg7he4U1ugYI2njTlvsrM6KhJcY5DgHo3zxCbQIsckHOsjE/k5c3zaRGH199Obw=',
});

module.exports = alipaySdk;





5, server/routes/index.js
var express = require('express');
var router = express.Router();
var connection = require('../db/sql.js');
var user = require('../db/userSql.js');
var QcloudSms = require("qcloudsms_js");
let jwt = require('jsonwebtoken');

// 引入支付宝配置文件
const alipaySdk = require('../db/alipay.js');
const AlipayFormData = require('alipay-sdk/lib/form').default;

// const express = require('express');
const cors = require('cors');
const app = express();
app.use(express.json());
app.use(cors());



// const bodyParser = require('body-parser');
// app.use(bodyParser.json()); // 解析请求体 

/* GET home page. */
router.get('/', function(req, res, next) {
	res.render('index', {
		title: 'Express'
	});
});


// 解析json格式的数据,否则 post 请求中 req.body 为 undefined
app.use(express.json())


// 发起支付 接口(后端)
router.post('/api/submitOrder', function(req, res, next) {
	// 以下几个参数是前端给后端传的数据
	// 订单号
	let orderId = req.body.orderId;

	// 商品总价
	let price = req.body.price;

	// 购买商品的名称
	let name = req.body.name;

	// 开始对接支付宝API(SDK)
	const formData = new AlipayFormData();

	// 调用 setMethod 并传入 get,会返回可以跳转到支付页面的 url
	formData.setMethod('get');

	// 支付时信息
	// get method 需要确保 field 都是字符串
	// 老师的
	formData.addField('bizContent', {
		// 订单号
		outTradeNo: 'orderId',
		// 写死的
		productCode: 'FAST_INSTANT_TRADE_PAY',
		// 商品总价格 
		totalAmount: price,
		// 商品名称
		subject: name
	});


	// 自己的
	// formData.addField('bizContent', JSON.stringify({
	// 	// 订单号
	// 	outTradeNo: 'orderId',
	// 	// 写死的
	// 	productCode: 'FAST_INSTANT_TRADE_PAY',
	// 	// 商品总价格 
	// 	totalAmount: price,
	// 	// 商品名称
	// 	subject: name
	// }));

	// 支付成功或者失败跳转链接
	formData.addField('returnUrl', 'http://localhost:8080/payment');

	// 返回 promise
	const result = alipaySdk.exec(
		'alipay.trade.page.pay', {}, {
			formData: formData
		},
	);
	// 对接支付宝成功,支付宝方返回的数据
	result.then(resp => {
		res.send({
			data: {
				code: 200,
				success: true,
				msg: '支付中',
				paymentUrl: resp
			}
		})
	})
})


// 修改订单状态  提交订单 后端接口
router.post('/api/submitOrder', function(req, res, next) {
	// 拿到 token ,并且去解析
	let token = req.headers.token;
	let tokenObj = jwt.decode(token); // 解析

	// 拿到订单号
	let orderId = req.body.orderId;

	// 拿到购物车选中的商品 id
	let shopArr = req.body.shopArr;

	// 查询当前用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// 用户id
		let uId = results[0].id;

		// 查询当前用户对应的订单,然后将他的状态改变
		connection.query(`select * from stroe_order where uId=${uId} and order_id=${orderId}`,
			function(err, result) {
				// 订单的数据库 id, 拿到对应订单的 id
				let id = result[0].id;

				// 修改订单状态 从 '1' 改为 '2'
				connection.query(
					`update store_order set order_status=replace(order_status,'1','2') where id=${id}`,
					function(e, r) {
						// 删除购物车数据
						shopArr.forEach(v => {
							// 删除操作  删除购物车表中的数据(注意!!!)
							connection.query(`delete from goods_cart where id=${v}`,
								function() {
									res.send({
										data: {
											code: 200,
											success: true
										}
									})
								})
						})
					})
			})
	})
})


// 查询订单(后端)
router.post('/api/selectOrder', function(req, res, next) {
	// 后端接收到前端传递的订单号 接收前端给后端的订单号
	let order_id = req.body.orderId;

	// 提交订单结束 后端给前端返回订单号数据
	connection.query(
		`select * from store_order where order_id='${orderId}'`,
		function(err, result) {
			// 返回
			res.send({
				data: {
					success: true,
					code: 200,
					// 返回订单号 字符串
					// data: result[0].order_id
					// 返回数组
					data: result
				}
			})
		})
})



// 生成一个订单 接口
router.post('/api/addOrder', function(req, res, next) {
	// 拿到 token ,并且去解析
	let token = req.headers.token;
	let tokenObj = jwt.decode(token); // 解析

	// 前端给后端的数据
	let goodsArr = req.body.arr;

	// 生成订单号 order_id 这个字段 规则 时间戳 + 6 位随机数
	function setTimeDateFmt(s) {
		// 补零规则
		return s < 10 ? '0' + s : s
	}

	// 生成订单号函数
	function radomNumber() {
		const now = new Date(); // 时间
		let month = now.getMonth() + 1;
		let day = now.getDate();
		let hour = now.getHours();
		let minutes = now.getMinutes();
		let seconds = now.getSeconds();

		month = setTimeDateFmt(month);
		day = setTimeDateFmt(day);
		hour = setTimeDateFmt(hour);
		minutes = setTimeDateFmt(minutes);
		seconds = setTimeDateFmt(seconds);

		// 生成订单号
		let orderCode = now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math
			.round(Math.random() * 1000000)).toString();

		return orderCode;
	}

	/* 订单状态
	未支付: 1
	待支付: 2
	支付成功: 3
	支付失败: 4 | 0
	*/

	// 商品列表名称
	let goodsName = [];

	// 订单商品总金额
	let goodsPrice = 0;

	// 订单商品总数量
	let goodsNum = 0;

	// 订单号
	let orderId = radomNumber();

	// 将 goodsArr 进行遍历
	goodsArr.forEach(v => {
		goodsName.push(v.goods_name);
		goodsPrice += v.goods_price * v.goods_num;
		goodsNum += parseInt(v.goods_num);
	})


	// 查询当前用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// 用户id
		let uId = results[0].id;

		// 存储
		connection.query(
			`insert into store_order (order_id,goods_name,goods_price,goods_num,order_status,uId) values ('${orderId}','${goodsName}','${goodsPrice}','${goodsNum}','1',${uId})`,
			function() {
				// 提交订单结束 后端给前端返回订单号数据
				connection.query(
					`select * from store_order where uId={uId} and order_id='${orderId}'`,
					function(err, result) {
						// 返回
						res.send({
							data: {
								success: true,
								code: 200,
								// 返回订单号 字符串
								// data: result[0].order_id
								// 返回数组
								data: result
							}
						})
					})
			}
		)
	})
})


// 删除收货地址 接口
router.post('/api/deleteAddress', function(req, res, next) {
	// 后端获取前端发送请求的 id
	let id = req.body.id;

	// 后端发送给数据库=>删除的sql语句
	connection.query(`delete from address where id = ${id}`, function(error, results) {
		// 返回
		res.send({
			data: {
				code: 200,
				success: true,
				msg: '删除成功'
			}
		})
	})
})


// 修改收货地址 修改当前用户的收货地址接口
router.post('/api/updateAddress', function(req, res, next) {
	// 拿到 token ,并且去解析
	let token = req.headers.token;
	let tokenObj = jwt.decode(token); // 解析

	// 解析
	let body = req.body;

	// 拿到前端传递后端的新增用户的所有信息
	let [id, name, tel, province, city, county, addressDetail, isDefault, areaCode, country,
		postalCode
	] = [
		body.id,
		body.name,
		body.tel,
		body.province,
		body.city,
		body.county,
		body.addressDetail,
		body.isDefault,
		body.areaCode,
		body.country,
		body.postalCode
	];

	// 查询当前用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// 用户id
		let uId = results[0].id;

		// 对应查询到 1 或者 0 查询之前有没有默认收货地址 
		connection.query(`select * from address where id=${uId} and isDefault=${isDefault}`,
			function(err, result) {
				if (result.length > 0) {
					// 拿到当前用户的ID
					let addressId = result[0].id;

					// 修改 isDefault 的值
					connection.query(
						`update address isDefault=replace(isDefault,"1","0") where id=${addressId}`,
						function(e, r) {
							// 修改
							let updateSql =
								`update address set uId=?, name=?, tel=?, province=?, city=?, county=?, addressDetail=?, isDefault=?, areaCode=?, country=?,postalCode=? where id = ${addressId}`;
							connection.query(updateSql, [uId, name, tel, province, city, county,
								addressDetail, isDefault, areaCode, country, postalCode
							], function(errors, resultss) {
								// 返回
								res.send({
									data: {
										code: 200,
										success: true,
										msg: '修改成功'
									}
								})
							})
						})
				} else {
					// 修改
					let updateSql =
						`update address set uId=?, name=?, tel=?, province=?, city=?, county=?, addressDetail=?, isDefault=?, areaCode=?, country=?,postalCode=? where id = ${addressId}`;
					connection.query(updateSql, [uId, name, tel, province, city, county,
						addressDetail, isDefault, areaCode, country, postalCode
					], function(errors, resultss) {
						// 返回
						res.send({
							data: {
								code: 200,
								success: true,
								msg: '修改成功'
							}
						})
					})
				}
			})
	})
})


// 查询收货地址 查询当前用户的收货地址接口
router.post('/api/selectAddress', function(req, res, next) {
	// 拿到 token ,并且去解析
	let token = req.headers.token;
	let tokenObj = jwt.decode(token); // 解析

	// 查询当前用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// 用户id
		let uId = results[0].id;

		// 查询对应表中的数据
		connection.query(`select * from address where uId=${uId}`, function(err, result) {
			// 返回
			res.send({
				data: {
					code: 200,
					success: true,
					msg: '查询成功',
					data: result
				}
			})
		})
	})
})


// 新增收货地址接口(后端)
router.post('/api/addAddress', function(req, res, next) {
	// 拿到前端给后端传递的数据
	// console.log(req.body);

	// 拿到 token ,并且去解析
	let token = req.headers.token;
	let tokenObj = jwt.decode(token); // 解析

	// 解析
	let body = req.body;

	// 拿到前端传递后端的新增用户的所有信息
	let [name, tel, province, city, county, addressDetail, isDefault, areaCode, country, postalCode] = [
		body.name,
		body.tel,
		body.province,
		body.city,
		body.county,
		body.addressDetail,
		body.isDefault,
		body.areaCode,
		body.country,
		body.postalCode
	];

	// 拿到信息后我们要去数据库查询
	// 查询当前用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// 用户id
		let uId = results[0].id;

		// 判断
		if (isDefault != 1) {
			// 增加一条收货地址
			connection.query(
				`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault,areaCode,country,postalCode) values ("${uId}","${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}","${areaCode}","${country}","${postalCode}")`,
				function() {
					res.send({
						data: {
							code: 200,
							success: true,
							msg: '收货地址添加成功'
						}
					})
				})
		} else {
			// 查询 然后将其他所有地址的 isDefault 的值修改为0
			connection.query(`select * from address where uId=&{uId} and isDefault=${isDefault}`,
				function(err, result) {
					// 判断
					if (result.length > 0) {
						// 获取 Id
						let addressId = result[0].id;

						// 修改 isDefault 的值
						connection.query(
							`update address set isDefault=replace(isDefault,"1","0") where uId=${addressId}`,
							function() {
								// 增加一条收货地址
								connection.query(
									`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault,areaCode,country,postalCode) values ("${uId}","${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}","${areaCode}","${country}","${postalCode}")`,
									function(e,
										r) {
										res.send({
											data: {
												code: 200,
												success: true,
												msg: '收货地址添加成功'
											}
										})
									})
							}
						)
					} else {
						// 增加一条收货地址
						connection.query(
							`insert into address (uId,name,tel,province,city,county,addressDetail,isDefault,areaCode,country,postalCode) values ("${uId}","${name}","${tel}","${province}","${city}","${county}","${addressDetail}","${isDefault}","${areaCode}","${country}","${postalCode}")`,
							function() {
								res.send({
									data: {
										code: 200,
										success: true,
										msg: '收货地址添加成功'
									}
								})
							})
					}
				})
		}
	})
})


// 修改购物车数据接口 (后端)
router.post('/api/updateNum', function(req, res, next) {
	// 获取前端传递的 id和num
	let id = req.body.id;
	let changeNum = req.body.num;

	// 查询当前商品的 id 号
	connection.query(`select * from goods_cart where id=${id}`, function(error, results) {
		// 原来数据库中商品的数量
		let num = results[0].goods_num;

		// 修改数据库中商品的数据量
		connection.query(
			`update goods_cart set goods_num=replace(goods_num,${num},${changeNum}) where id=${id});`,
			function(err, result) {
				// 发送数据
				res.send({
					data: {
						code: 200,
						success: true
						// msg: '修改成功'
					}
				})
			})
	})
})


// 删除购物车数据接口(后端)
router.post('/api/deleteCart', function(req, res, next) {
	// 接收前端给后端传递的id
	let arrId = req.body.arrId;

	for (let i = 0; i < arrId.length; i++) {
		// 进入到sql语句,执行数据删除命令
		connection.query(`delete from goods_cart where id=${arrId[i]}`, function(error, results) {
			res.send({
				data: {
					code: 200,
					success: true,
					msg: '删除成功'
				}
			})
		})
	}
})

// 查询购物车数据接口(后端)
router.post('/api/selectCart', function(req, res, next) {
	// 拿到 token ,并且去解析
	let token = req.headers.token;
	let tokenObj = jwt.decode(token); // 解析

	// 查询用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// 用户id
		let uId = results[0].id;

		// 查询购物车
		connection.query(`select * from goods_cart where uId = ${uId}`, function(err, result) {
			res.send({
				data: {
					code: 200,
					success: true,
					data: result
				}
			})
		})
	})
})

// 添加购物车数据接口
router.post('/api/addCart', function(req, res, next) {
	// 后端接收前端的参数
	let goodsId = req.body.goodsId;

	// token
	let token = req.headers.token;
	let tokenObj = jwt.decode(token);

	// 查询用户
	connection.query(`select * from users where tel=${tokenObj.tel}`, function(error, results) {
		// console.log(results[0]);

		// 用户id
		let uId = results[0].id;

		// 查询商品
		connection.query(`select * from goods_list where id=${goodsId}`, function(err, result) {
			// console.log(result[0]);
			let goodsName = result[0].name;
			let goodsPrice = result[0].price;
			// let goodsNum = result[0].num;
			let goodsImgUrl = result[0].imgUrl;


			// 查询当前用户在这之前是否添加过本商品,如果有我们就做增加处理,
			// 如果没有该商品,我们就做添加处理
			connection.query(
				`select * from goods_cart where uId=${uId} and goods_id=${goodsId}`,
				function(e, r) {

					// 判断当前用户之前是否添加过本商品到购物车
					if (r.length > 0) {
						let num = r[0].goods_num;
						// 表示之前有添加该商品==>做增加处理 即替换处理
						connection.query(
							`update goods_cart set goods_num=replace(goods_num, ${num},${parseInt(num)+1}) where id=${r[0].id}`,
							function(e, datas) {
								// 返回
								res.send({
									data: {
										code: 200,
										success: true,
										msg: '添加成功'
									}
								})
							}
						)
					} else {
						// 没有该商品==>做添加处理
						// 添加购物车数据
						connection.query(
							`insert into goods_cart(uid,goods_id,goods_name,goods_price,goods_num,goods_imgUrl) values ("${uId}","${goodsId}","${goodsName}","${goodsPrice}","1","${goodsImgUrl}")`,
							function() {
								res.send({
									data: {
										code: 200,
										success: true,
										msg: '添加成功'
									}
								})
							})
					}
				})
		})
	})
})

// 修改密码接口
router.post('/api/recovery', function(req, res, next) {
	// 先接收前端传递给后端的数据
	let params = {
		userTel: req.body.phone,
		userPwd: req.body.pwd
	}

	// 查询用户是否存在
	connect.query(user.queryUserTel(params), function(error, results) {
		// 先查询某一条数据在不在,在拿到该记录数的id,然后修改该条记录的密码
		// 数据库的数据id 拿到用户id 某一条记录数id
		let id = results[0].id;
		let pwd = results[0].pwd;

		// 修改用户密码
		connection.query(
			`uplate users set pwd=replace(pwd, "${pwd}","${params.userPwd}") where id = ${id}`,
			function(err, results) {
				res.send({
					code: 200,
					data: {
						success: true,
						msg: '修改成功'
					}
				})
			})
	})
})

// 查询用户是否存在
router.post('/api/selectUser', function(req, res, next) {

	// 拿到前端传递的数据
	let params = {
		userTel: req.body.phone
	}

	// 查询用户是否存在
	connect.query(user.queryUserTel(params), function(error, results) {
		if (results.length > 0) {
			res.send({
				code: 200,
				data: {
					success: true
				}
			})
		} else {
			res.send({
				code: 0,
				data: {
					success: false,
					msg: '此用户不存在'
				}
			})
		}
	})
})



// 注册
router.post('/api/register', function(req, res, next) {
	// 拿到前端传递的数据
	let params = {
		userTel: req.body.phone,
		userPwd: req.body.pwd
	}

	// 查询用户是否存在
	connect.query(user.queryUserTel(params), function(error, results) {
		// 如果有错误就抛出错误
		if (error) throw error;

		// 判断用户是否存在
		if (results.length > 0) {
			// 用户存在,直接返回
			res.send({
				code: 200,
				data: {
					success: true,
					msg: '登录成功',
					data: results[0]
				}
			})
		} else {
			// 用户不存在,新增一条数据
			connection.query(user.insertData(params), function(err, result) {
				// 新增数据后,再把新增数据查询一下,看看有没有添加成功
				connection.query(user.queryUserTel(params), function(e, r) {
					// 用户存在,直接返回
					res.send({
						code: 200,
						data: {
							success: true,
							msg: '登录成功',
							data: r[0]
						}
					})
				})
			})
		}
	})
})


// 增加一个用户
router.post('/api/addUser', function(req, res, next) {
	let params = {
		userTel: req.body.phone
	}

	// let tel = {
	// 	userTel: req.body.phone
	// }

	// 查询用户是否存在
	connect.query(user.queryUserTel(params), function(error, results) {
		// 如果有错误就抛出错误
		if (error) throw error;

		// 判断用户是否存在
		if (results.length > 0) {
			// 用户存在,直接返回
			res.send({
				code: 200,
				data: {
					success: true,
					msg: '登录成功',
					data: results[0]
				}
			})
		} else {
			// 用户不存在,新增一条数据
			connection.query(user.insertData(params), function(err, result) {
				// 新增数据后,再把新增数据查询一下,看看有没有添加成功
				connection.query(user.queryUserTel(params), function(e, r) {
					// 用户存在,直接返回
					res.send({
						code: 200,
						data: {
							success: true,
							msg: '登录成功',
							data: r[0]
						}
					})
				})
			})
		}
	})
})


// 请求短信验证码接口
router.post('/api/code', function(req, res, next) {

	// 后端接收前端发送的手机号	 
	let tel = req.body.phone;

	// 短信应用SDK AppID
	// var appid = 1400187558; // 老师的
	var appid = 1400979236; // 自己的 SDK AppID是1400开头  1400979236	   1400009099

	// 短信应用SDK AppKey
	// var appkey = "9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad";
	var appkey = "10fd4851f4228eb21e670ee72fe932f2"; // 自己的
	// var appkey = "dc9dc3391896235ddc2325685047edc7"; // 老师的

	// 需要发送短信的手机号码
	// var phoneNumbers = ["18017927192", "15300935233"];
	var phoneNumbers = [tel]

	// 短信模板ID,需要在短信应用中申请
	var templateId = 285590; // 老师的 NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请

	// 签名
	var smsSign = "三人行慕课"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID`

	// 实例化QcloudSms
	var qcloudsms = QcloudSms(appid, appkey);

	// 设置请求回调处理, 这里只是演示,用户需要自定义相应处理回调
	function callback(err, ress, resData) {
		if (err) {
			console.log("err: ", err);
		} else {
			res.send({
				code: 200,
				data: {
					success: true,
					data: ress.req.body.params[0]
				}
			})
			// console.log("request data: ", ress.req);
			// console.log("response data: ", resData);
		}
	}

	// 指定模板ID单发短信
	var ssender = qcloudsms.SmsSingleSender();
	// 这个变量 params 就是往手机上发送的短信
	var params = [Math.floor(Math.random() * (9999 - 1000)) + 1000];
	ssender.sendWithParam(86, phoneNumbers[0], templateId,
		params, smsSign, "", "", callback); // 签名参数不能为空串
})


// 登录接口 /api/login
router.post('/api/login', function(req, res, next) {
	// 后端要接收前端传递过来的值(数据)
	let params = {
		userTel: req.body.userTel,
		userPwd: req.body.userPwd
	};

	// 查询数据库中用户手机号是否存在
	connection.query(user.queryUserTel(params), function(error, results) {
		// 判断手机号存在是否存在
		if (results.length > 0) {
			//手机号存在
			connection.query(user.queryUserPwd(params), function(err, result) {
				//判断手机号和密码
				if (result.length > 0) {
					// 手机号和密码都对
					res.send({
						code: 200,
						data: {
							success: true,
							msg: '登录成功',
							data: result[0]
						}
					})
				} else {
					// 密码不对
					res.send({
						code: 302,
						data: {
							success: false,
							msg: '密码不正确'
						}
					})
				}
			})
		} else {
			// 手机号不存在
			res.send({
				code: 301,
				data: {
					success: false,
					msg: '手机号不存在'
				}
			})
		}
	})
})




// 查询商品id的数据接口
router.get('/api/goods/id', function(req, res, next) {
	// 获取 前端给后端传递的 id 号
	let id = req.query.id;

	// 查询数据库
	connection.query(`select * from goods_list where id=${id}`, function(error, results) {
		if (error) throw error;
		res.json({
			code: 0,
			// data: results // 后端给前端返回的数据为数组,需要解析
			data: results[0] // 后端给前端返回的数据为对象
		})
	})

	// connection.query(`select * from space_store where id= '+id+'`, function(error, results) {
	// 	if (error) throw error;
	// 	res.json({
	// 		code: 0,
	// 		// data: results // 后端给前端返回的数据为数组,需要解析
	// 		data: results[0] // 后端给前端返回的数据为对象
	// 	})
	// })
})


// 分类的接口
router.get('/api/goods/list', function(req, res, next) {
	res.send({
		code: 0,
		data: [{
			// 一级
			id: 0,
			name: '推荐',
			data: [{
				// 二级
				id: 0,
				name: '推荐',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 1,
			name: '新品',
			data: [{
				// 二级
				id: 1,
				name: '新品',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 2,
			name: '习茶',
			data: [{
				// 二级
				id: 2,
				name: '习茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 3,
			name: '绿茶',
			data: [{
				// 二级
				id: 3,
				name: '绿茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 4,
			name: '乌龙茶',
			data: [{
				// 二级
				id: 4,
				name: '乌龙茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 5,
			name: '红茶',
			data: [{
				// 二级
				id: 5,
				name: '红茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 6,
			name: '白茶',
			data: [{
				// 二级
				id: 6,
				name: '白茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 7,
			name: '普洱茶',
			data: [{
				// 二级
				id: 7,
				name: '普洱茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 8,
			name: '花茶',
			data: [{
				// 二级
				id: 8,
				name: '花茶',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 9,
			name: '茶具',
			data: [{
				// 二级
				id: 9,
				name: '茶具',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}, {
			// 一级
			id: 10,
			name: '手艺',
			data: [{
				// 二级
				id: 10,
				name: '手艺',
				list: [{
					// 三级
					id: 0,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}, {
					// 三级
					id: 1,
					name: '铁观音',
					imgUrl: '/images/tieguanyin.png'
				}, {
					// 三级
					id: 2,
					name: '金骏眉',
					imgUrl: '/images/jinjunmei.png'
				}, {
					// 三级
					id: 3,
					name: '武夷岩茶',
					imgUrl: '/images/wuyiyancha.png'
				}, {
					// 三级
					id: 4,
					name: '龙井',
					imgUrl: '/images/longjing.png'
				}, {
					// 三级
					id: 5,
					name: '云南滇红',
					imgUrl: '/images/yunnandianhong.png'
				}, {
					// 三级
					id: 6,
					name: '建盏',
					imgUrl: '/images/jianzhan.png'
				}, {
					// 三级
					id: 7,
					name: '功夫茶具',
					imgUrl: '/images/gonghuchaju.png'
				}, {
					// 三级
					id: 8,
					name: '紫砂壶',
					imgUrl: '/images/teapot.png'
				}]
			}]
		}]
	})
})

// 查询商品数据接口 后端写接口
router.get('/api/goods/shopList', function(req, res, next) {
	// 前端给后端的数据 拿到前端发过来的数据
	// let searchName = req.query.searchName;
	let [searchName, orderName] = Object.keys(req.query);
	let [name, order] = Object.values(req.query);
	// console.log(searchName, orderName, name, order);

	// console.log('results');
	// 查询数据库表
	connection.query('select * from goods_list where name like "%' + name +
		'%" order by "+orderName+" "+order+" ',
		function(error,
			results) {
			console.log('results');
			res.send({
				code: 0,
				data: results
			})
		})
})


// 首页推荐的数据  0==> 推荐  1==> 第一塀数据
router.get('/api/index_list/0/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			topBar: [{
				id: 0,
				label: '推荐'
			}, {
				id: 1,
				label: '大红袍'
			}, {
				id: 2,
				label: '铁观音'
			}, {
				id: 3,
				label: '绿茶'
			}, {
				id: 4,
				label: '普洱'
			}, {
				id: 5,
				label: '茶具'
			}, {
				id: 6,
				label: '花茶'
			}, {
				id: 7,
				label: '红茶'
			}, {
				id: 8,
				label: '设计'
			}, ],
			// 这是我们的swiper
			data: [{ // 这是swiper数据
				id: 0,
				type: 'swiperList',
				data: [{
					id: 1,
					imgUrl: './images/swiper4.png'
				}, {
					id: 2,
					imgUrl: './images/swiper5.png'
				}, {
					id: 3,
					imgUrl: './images/swiper6.png'
				}],
			}, { // 这是Icons数据
				id: 1,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}],
			}, { // 爆款推荐
				id: 2,
				type: 'recommendList',
				data: [{
					id: 1,
					name: '龙井1号铁观音250g',
					content: '鲜爽甘醇 口粮首先',
					price: '68',
					imgUrl: './images/recommend2.png'
				}, {
					id: 2,
					name: '龙井2号铁观音250g',
					content: '鲜爽甘醇 口粮首先',
					price: '58',
					imgUrl: './images/recommend2.png'
				}]
			}, {
				// 猜你喜欢
				id: 3,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 199,
				}, {
					id: 2,
					imgUrl: './images/like9.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like10.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 399,
				}, {
					id: 4,
					imgUrl: './images/like11.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 499,
				}, {
					id: 5,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 599,
				}, {
					id: 6,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 699,
				}, {
					id: 7,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 799,
				}, {
					id: 8,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 899,
				}, {
					id: 9,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 999,
				}, {
					id: 10,
					imgUrl: './images/like10.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 1099,
				}, {
					id: 11,
					imgUrl: './images/like11.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 1199,
				}]
			}]
		}
	})
});

// 首页大红袍的数据  1==> 大红袍  1==> 第一塀数据
router.get('/api/index_list/1/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/dhp.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页铁观音的数据  2==> 铁观音  1==> 第一塀数据
router.get('/api/index_list/2/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/tieguanyin1.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页绿茶的数据  3==> 绿茶  1==> 第一塀数据
router.get('/api/index_list/3/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/green_tea.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页普洱的数据  4==> 普洱  1==> 第一塀数据
router.get('/api/index_list/4/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/puer.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页茶具的数据  5==> 茶具  1==> 第一塀数据
router.get('/api/index_list/5/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/tea_sets.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页花茶的数据  6==> 花茶  1==> 第一塀数据
router.get('/api/index_list/6/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/scented.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页红茶的数据  7==> 红茶  1==> 第一塀数据
router.get('/api/index_list/7/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/jinjunmei.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// 首页设计的数据  8==> 设计   1==> 第一塀数据
router.get('/api/index_list/8/data/1', function(req, res, next) {
	res.send({
		code: 0,
		data: {
			data: [{
				id: 1,
				type: 'adList',
				data: [{
					id: 1,
					imgUrl: './images/design.png'
				}]
			}, { // 这是Icons数据
				id: 3,
				type: 'iconsList',
				data: [{
					id: 1,
					title: '自饮茶',
					imgUrl: './images/icons1.png'
				}, {
					id: 2,
					title: '茶具',
					imgUrl: './images/icons2.png'
				}, {
					id: 3,
					title: '茶礼盒',
					imgUrl: './images/icons3.png'
				}, {
					id: 4,
					title: '领取福利',
					imgUrl: './images/icons4.png'
				}, {
					id: 5,
					title: '官方验证',
					imgUrl: './images/icons5.png'
				}]
			}, {
				// 猜你喜欢
				id: 2,
				type: 'likeList',
				data: [{
					id: 1,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 2,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}, {
					id: 3,
					imgUrl: './images/like8.png',
					name: '建盏茶具套装 红色芝麻毫 12件套',
					price: 299,
				}]
			}]
		}
	})
});

// // 监听端口
// app.listen(3000, () => {
// 	console.log('服务启动成功,端口为3000')
// })

module.exports = router;
相关推荐
Tzarevich1 小时前
用 OOP 思维打造可复用的就地编辑组件:EditInPlace 实战解析
javascript·前端框架
用户8168694747251 小时前
Lane 优先级模型与时间切片调度
前端·react.js
虎头金猫1 小时前
MateChat赋能电商行业智能导购:基于DevUI的技术实践
前端·前端框架·aigc·ai编程·ai写作·华为snap·devui
LiuMingXin1 小时前
CESIUM JS 学习笔记 (持续更新)
前端·cesium
豆苗学前端1 小时前
面试复盘:谈谈你对 原型、原型链、构造函数、实例、继承的理解
前端·javascript·面试
Crystal3281 小时前
Git 基础:生成版本、撤消操作、版本重置、忽略文件
前端·git·github
lichenyang4531 小时前
React 组件通讯全案例解析:从 Context 到 Ref 的实战应用
前端
国服第二切图仔1 小时前
Electron for 鸿蒙pc项目实战之右键菜单组件
javascript·electron·harmonyos·鸿蒙pc
姓王者1 小时前
chen-er 专为Chen式ER图打造的npm包
前端·javascript