添加注册,修改登录

This commit is contained in:
yangj
2022-04-02 16:25:25 +08:00
parent aff5ed3912
commit 886a20bf49
13 changed files with 7263 additions and 134 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
package-lock.json

2
app.js
View File

@@ -2,7 +2,7 @@
var http = require("utils/http.js");
App({
onLaunch: function () {
http.getToken();
// http.getToken();
// wx.getSetting({
// success(res) {
// if (!res.authSetting['scope.userInfo']) {

119
app.json
View File

@@ -1,62 +1,61 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/user/user",
"pages/basket/basket",
"pages/category/category",
"pages/search-page/search-page",
"pages/delivery-address/delivery-address",
"pages/editAddress/editAddress",
"pages/orderList/orderList",
"pages/order-detail/order-detail",
"pages/submit-order/submit-order",
"pages/binding-phone/binding-phone",
"pages/express-delivery/express-delivery",
"pages/pay-result/pay-result",
"pages/search-prod-show/search-prod-show",
"pages/prod/prod",
"pages/login/login",
"pages/prod-classify/prod-classify",
"pages/recent-news/recent-news",
"pages/news-detail/news-detail"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"tabBar": {
"selectedColor": "#3a86b9",
"color": "#b8b8b8",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "images/tabbar/homepage.png",
"selectedIconPath": "images/tabbar/homepage-sel.png"
},
{
"pagePath": "pages/category/category",
"text": "分类",
"iconPath": "images/tabbar/category.png",
"selectedIconPath": "images/tabbar/category-sel.png"
},
{
"pagePath": "pages/basket/basket",
"text": "购物车",
"iconPath": "images/tabbar/basket.png",
"selectedIconPath": "images/tabbar/basket-sel.png"
},
{
"pagePath": "pages/user/user",
"text": "我的",
"iconPath": "images/tabbar/user.png",
"selectedIconPath": "images/tabbar/user-sel.png"
}
]
},
"sitemapLocation": "sitemap.json"
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/user/user",
"pages/basket/basket",
"pages/category/category",
"pages/search-page/search-page",
"pages/delivery-address/delivery-address",
"pages/editAddress/editAddress",
"pages/orderList/orderList",
"pages/order-detail/order-detail",
"pages/submit-order/submit-order",
"pages/binding-phone/binding-phone",
"pages/express-delivery/express-delivery",
"pages/pay-result/pay-result",
"pages/search-prod-show/search-prod-show",
"pages/prod/prod",
"pages/login/login",
"pages/prod-classify/prod-classify",
"pages/recent-news/recent-news",
"pages/news-detail/news-detail"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"tabBar": {
"selectedColor": "#3a86b9",
"color": "#b8b8b8",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "images/tabbar/homepage.png",
"selectedIconPath": "images/tabbar/homepage-sel.png"
},
{
"pagePath": "pages/category/category",
"text": "分类",
"iconPath": "images/tabbar/category.png",
"selectedIconPath": "images/tabbar/category-sel.png"
},
{
"pagePath": "pages/basket/basket",
"text": "购物车",
"iconPath": "images/tabbar/basket.png",
"selectedIconPath": "images/tabbar/basket-sel.png"
},
{
"pagePath": "pages/user/user",
"text": "我的",
"iconPath": "images/tabbar/user.png",
"selectedIconPath": "images/tabbar/user-sel.png"
}
]
},
"sitemapLocation": "sitemap.json"
}

File diff suppressed because it is too large Load Diff

18
package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "mall4m",
"version": "1.0.0",
"description": "一个基于vue、element ui 的轻量级、前后端分离、拥有完整sku和下单流程的完全开源商城 小程序端",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitee.com/gz-yami/mall4m.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"crypto-js": "^4.1.1"
}
}

View File

@@ -26,7 +26,6 @@ Page({
},
onLoad: function() {
this.getAllData();
},
// 页面滚动到指定位置指定元素固定在顶部
@@ -80,17 +79,6 @@ Page({
},
onShow: function() {
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userInfo']) {
wx.navigateTo({
url: '/pages/login/login',
})
}
}
})
http.getCartCount(); //重新计算购物车总数量
},
getAllData() {
http.getCartCount(); //重新计算购物车总数量

View File

@@ -1,11 +1,17 @@
var http = require("../../utils/http.js");
var crypto = require("../../utils/crypto.js");
Page({
/**
* 页面的初始数据
*/
data: {
// 用户名
userName: '',
// 密码
password: '',
// 是否显示注册
isRegister: false
},
onGotUserInfo: function (res) {
@@ -19,7 +25,9 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
isRegister: options.isRegister == 0
})
},
/**
@@ -69,5 +77,66 @@ Page({
*/
onShareAppMessage: function () {
},
/**
* 输入框的值
*/
getInputVal: function(e) {
const type = e.currentTarget.dataset.type
if (type == 'account') {
this.setData({
userName: e.detail.value
})
} else if (type == 'password') {
this.setData({
password: e.detail.value
})
}
},
/**
* 切换注册/登录
*/
handleChangeShowType() {
let str = this.data.isRegister ? '1' : '0'
wx.redirectTo({
url: '/pages/login/login?isRegister=' + str
})
},
/**
* 注册/登录按钮
*/
handleLoginOrRegister() {
if (!this.data.userName.trim()) {
wx.showToast({
title: '请输入用户名',
icon: 'none'
})
return
}
if (!this.data.password.trim()) {
wx.showToast({
title: '请输入密码',
icon: 'none'
})
return
}
const params = {
url: this.data.isRegister ? '/user/register' : '/login',
method: "POST",
data: {
userName: this.data.userName,
passWord: crypto.encrypt(this.data.password)
},
callBack: (res) => {
wx.setStorageSync('token', res.accessToken)
wx.reLaunc({
url: '/pages/index/index',
})
}
};
http.request(params);
}
})

View File

@@ -1,5 +1,26 @@
<!--pages/login/login.wxml-->
<image src='http://img-test.gz-yami.com/mini/logo.jpg' class='c-logo'></image>
<view class="title">mall4j</view>
<view class="msg">申请获得你的公开信息(昵称、头像等)</view>
<button color="#eb2444" open-type="getUserInfo" lang = "zh_CN" bindgetuserinfo = "onGotUserInfo" class=''>微信授权</button>
<view class="login-form">
<view class="item">
<view class="account">
<text class="input-item">用户名</text>
<input type="text" data-type="account" placeholder-class="inp-palcehoder" placeholder="请输入用户名" bindinput="getInputVal"></input>
</view>
</view>
<view class="item">
<view class="account">
<text class="input-item">密码</text>
<input type="password" data-type="password" placeholder-class="inp-palcehoder" placeholder="请输入密码" bindinput="getInputVal"></input>
</view>
</view>
<view>
<button class="authorized-btn" bindtap="handleLoginOrRegister">{{isRegister ? '注册': '登录'}}</button>
<button class="to-idx-btn" bindtap="goBack">回到首页</button>
</view>
<view class="operate">
<view class="to-register" bindtap="handleChangeShowType">
{{isRegister?'已有账号?去登录>' : '没有账号?去注册>'}}
</view>
</view>
</view>

View File

@@ -23,7 +23,7 @@ view.title {
color: #333;
width: 100%;
text-align: center;
margin-top: 20rpx;
margin: 20rpx 0;
}
button {
@@ -41,4 +41,106 @@ button {
.button-hover{
background-color: #fff;
color: #eb2444;
}
}
page{
background: #fff;
height: 100%;
}
.con{
padding-top: 100rpx;
}
.logo {
display: flex;
justify-content: center;
height: 150rpx;
margin-bottom: 8%;
}
.logo image {
display: block;
width: 100%;
height: 100%;
}
.login-form{
width: 90%;
margin: 0 auto;
margin-bottom: 10%;
}
.authorized-btn {
width: 100%;
margin: 0 auto;
text-align: center;
background-color: #0ab906;
border: 1rpx solid #0ab906;
color: #fff;
border-radius: 6rpx;
font-size: 26rpx;
margin-top: 60rpx;
}
.to-idx-btn{
width: 100%;
margin: 0 auto;
text-align: center;
background-color: #eeeeee;
border: 1rpx solid #eeeeee;
color: #333;
border-radius: 6rpx;
font-size: 26rpx;
margin-top: 30rpx;
}
.form-title {
width: 100%;
margin-bottom: 50rpx;
font-size: 32rpx;
text-align: center;
color: #00a0e9;
}
.item {
display: block;
margin-bottom: 30rpx;
}
.account{
display: flex;
background: #f8f8f8;
padding: 15rpx;
box-sizing: border-box;
font-size: 26rpx;
align-items: center;
}
.account input{
padding-left: 20rpx;
width:75%;
}
.inp-palcehoder{
font-size: 26rpx;
}
.account input.int-yzm {
width: 410rpx;
padding-right: 10rpx;
box-sizing: border-box;
}
.input-btn {
width: 152rpx;
font-size: 26rpx;
color: #00a0ea;
text-align: center;
}
button::after{
border: 0 !important;
}
/* 去注册 */
.operate {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20rpx;
}
.forgot-password,
.to-register {
font-size: 28rpx;
color: #00AAFF;
}

View File

@@ -1,47 +1,62 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"nodeModules": false,
"autoAudits": false,
"checkInvalidKey": true
},
"compileType": "miniprogram",
"libVersion": "2.6.4",
"appid": "wx6fa71e69231a4fa4",
"projectname": "mall4j",
"debugOptions": {
"hidedInDevtools": []
},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"conversation": {
"current": -1,
"list": []
"setting": {
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": false,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": false,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"disableUseStrict": false,
"ignoreUploadUnusedFiles": true,
"minifyWXML": true
},
"plugin": {
"current": -1,
"list": []
"compileType": "miniprogram",
"libVersion": "2.23.2",
"appid": "wx6fa71e69231a4fa4",
"projectname": "mall4j",
"debugOptions": {
"hidedInDevtools": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"list": []
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"plugin": {
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"list": []
}
}
}
}
}

View File

@@ -1,6 +1,6 @@
//可改动页面
var domain = "http://127.0.0.1:8086"; //统一接口域名,测试环境
var domain = "http://192.168.1.17:8386"; //统一接口域名,测试环境
exports.domain = domain;

11
utils/crypto.js Normal file
View File

@@ -0,0 +1,11 @@
import CryptoJS from 'crypto-js'
// 加密
const keyStr = '-mall4j-password' // 解密用的key
export function encrypt(word) {
const time = Date.now()
const key = CryptoJS.enc.Utf8.parse(keyStr)
const srcs = CryptoJS.enc.Utf8.parse(time + word) // 加密方式: 时间戳 + 密文
const encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
return encrypted.toString()
}

View File

@@ -5,10 +5,10 @@ function request(params, isGetTonken) {
// 全局变量
var globalData = getApp().globalData;
// 如果正在进行登陆,就将非登陆请求放在队列中等待登陆完毕后进行调用
if (!isGetTonken && globalData.isLanding) {
globalData.requestQueue.push(params);
return;
}
// if (!isGetTonken && globalData.isLanding) {
// globalData.requestQueue.push(params);
// return;
// }
wx.request({
url: config.domain + params.url, //接口请求地址
data: params.data,
@@ -32,14 +32,17 @@ function request(params, isGetTonken) {
icon: "none"
});
} else if (res.statusCode == 401) {
// 添加到请求队列
globalData.requestQueue.push(params);
// 是否正在登陆
if (!globalData.isLanding) {
globalData.isLanding = true
//重新获取token,再次请求接口
getToken();
}
wx.navigateTo({
url: '/pages/login/login',
})
// // 添加到请求队列
// globalData.requestQueue.push(params);
// // 是否正在登陆
// if (!globalData.isLanding) {
// globalData.isLanding = true
// //重新获取token,再次请求接口
// getToken();
// }
} else if (res.statusCode == 400) {
wx.showToast({
title: res.data,