1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

小程序登录逻辑跑通;登陆密码MD5存储;小程序首页添加调试输出

This commit is contained in:
程序员小墨 2022-11-24 02:06:50 +08:00
parent d28fa0dd00
commit 08bab25a48
9 changed files with 161 additions and 61 deletions

View File

@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
@ -22,7 +23,7 @@ public class UserController {
// @RequestMapping("/login")
@PostMapping("/login")
@ResponseBody
public Res login(String username, String password) {
public Res login(@RequestParam("username") String username, @RequestParam("password") String password) {
User user = userService.getUserByUsername(username);
if (user != null) {
String passwordHash = user.getPassword();

File diff suppressed because one or more lines are too long

View File

@ -23,6 +23,7 @@
"@tarojs/shared": "3.5.7",
"@tarojs/taro": "3.5.7",
"@tarojs/taro-h5": "3.5.7",
"blueimp-md5": "^2.19.0",
"vue": "^3.0.0"
},
"devDependencies": {
@ -5994,6 +5995,11 @@
"safe-buffer": "^5.1.1"
}
},
"node_modules/blueimp-md5": {
"version": "2.19.0",
"resolved": "https://registry.npmmirror.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w=="
},
"node_modules/body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.20.1.tgz",
@ -26696,6 +26702,11 @@
"safe-buffer": "^5.1.1"
}
},
"blueimp-md5": {
"version": "2.19.0",
"resolved": "https://registry.npmmirror.com/blueimp-md5/-/blueimp-md5-2.19.0.tgz",
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w=="
},
"body-parser": {
"version": "1.20.1",
"resolved": "https://registry.npmmirror.com/body-parser/-/body-parser-1.20.1.tgz",

View File

@ -50,6 +50,7 @@
"@tarojs/shared": "3.5.7",
"@tarojs/taro": "3.5.7",
"@tarojs/taro-h5": "3.5.7",
"blueimp-md5": "^2.19.0",
"vue": "^3.0.0"
},
"devDependencies": {

View File

@ -2,7 +2,7 @@
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "epp",
"setting": {
"compileHotReLoad": true,
"compileHotReLoad": false,
"urlCheck": false
}
}

View File

@ -10,7 +10,8 @@ const App = createApp({
// 全局变量 refer: https://docs.taro.zone/docs/come-from-miniapp#%E5%85%A8%E5%B1%80%E5%8F%98%E9%87%8F
App.use(setGlobalDataPlugin, {
globalData: {
baseUrl: "http://localhost:8080", // 不带最后的 /
debugMode: true, // 是否展示调试内容
baseUrl: "http://localhost", // 不带最后的 /
}
})

View File

@ -4,6 +4,24 @@
<view style="display: block; padding-left: 30px; padding-top: 12px;">
<text>欢迎你{{ displayUsername }}</text>
</view>
<view style="display: block;" v-if="isVisitor">
<view style="display: flex;text-align: center;margin-top: 20px;">
<view style="width: 25%;">
<image src="../../image/icon/code.png" style="width: 40px;height: 40px;" @tap='goCode'></image>
<view>进出码</view>
</view>
<view style="width: 25%;">
<image src="../../image/icon/feedback.png" style="width: 40px;height: 40px;" bindtap='goFeedback'></image>
<view>反馈查看</view>
</view>
<view style="width: 25%;">
<image src="../../image/icon/apply.png" style="width: 40px;height: 40px;" bindtap='goApply'></image>
<view>申请记录</view>
</view>
</view>
</view>
<view style="display: block;" v-if="isUser">
<view style="display: flex;text-align: center;margin-top: 20px;">
<view style="width: 25%;">
@ -39,6 +57,7 @@
</view>
</view>
</view>
<view style="display: block;" v-if="isAdmin">
<view style="display: flex;text-align: center;margin-top: 20px;">
<view style="width: 25%;">
@ -76,28 +95,39 @@
</view>
</view>
</view>
<view v-if="debugMode">
<button @tap='debugCleanCache'>清除缓存</button>
<text decode="nbsp">{{ debugText }}</text>
</view>
</template>
<script>
import Taro from '@tarojs/taro'
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
import ENUM from '../../utils/const.js'
import './index.css'
export default {
setup() {
},
data() {
return {
userInfo: null,
displayUsername: "",
isVisitor: false,
isUser: false,
isAdmin: false,
debugMode: Taro.getApp().globalData.debugMode,
debugText: "",
}
},
mounted() {
eventCenter.once(getCurrentInstance().router.onShow, () => {
console.log('onShow')
console.log("ENUM", ENUM)
console.log("debugMode", this.debugMode)
this.userInfo = Taro.getStorageSync("userInfo");
this.displayUsername = this.userInfo?.username ?? "请登录";
if (!this.userInfo) {
@ -106,8 +136,30 @@ export default {
url: '/pages/index/login'
})
} else {
this.isUser = this.userInfo.userType == "user";
this.isAdmin = this.userInfo.userType == "admin";
const role = ENUM.user.role;
this.isVisitor = [
role.VISITOR,
].includes(this.userInfo.role);
this.isUser = [
role.RESIDENTS_OWNER,
role.RESIDENTS_MEMBER,
role.RESIDENTS_TENENT,
].includes(this.userInfo.role);
this.isAdmin = [
role.ADMIN,
role.STAFF,
].includes(this.userInfo.role);
console.log(
"isVisitor", this.isVisitor,
"isUser", this.isUser,
"isAdmin", this.isAdmin
)
this.debugText = JSON.stringify({
"isVisitor": this.isVisitor,
"isUser": this.isUser,
"isAdmin": this.isAdmin,
"userInfo": this.userInfo
}, null, 4).replace(/[ ]/g, '&nbsp;&nbsp;')
}
})
},
@ -119,6 +171,19 @@ export default {
Taro.switchTab({
url: '/pages/residents/code'
})
},
debugCleanCache() {
Taro.clearStorage({
success: function () {
Taro.showToast({
title: "成功",
icon: 'success'
})
Taro.reLaunch({
url: '/pages/index/index'
})
}
})
}
}
}

View File

@ -22,6 +22,7 @@
<script>
import Taro from '@tarojs/taro'
import md5 from 'blueimp-md5'
import './login.css'
@ -42,40 +43,45 @@ export default {
duration: 2000
})
} else {
let passwordHash = md5(this.password);
Taro.request({
url: `${this.baseUrl}/user/login`,
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded" //post
},
data: {
username: this.username,
password: this.password,
password: passwordHash,
},
success: function (d) {
let data = d.data;
if (data.code == 200) {
if (data.status == "success") {
Taro.setStorageSync("userInfo", data.userInfo);
console.log("userInfo", Taro.getStorageSync("userInfo"))
Taro.showToast({
title: "登录成功",
icon: 'success',
success: function () {
Taro.redirectTo({
url: '/pages/index/index'
})
}
})
} else {
Taro.showToast({
title: data.msg,
icon: 'error'
})
}
let result = d.data;
if (result.success) {
Taro.setStorageSync("userInfo", result.data.userInfo);
console.log("userInfo", Taro.getStorageSync("userInfo"))
Taro.showToast({
title: "登录成功",
icon: 'success',
success: function () {
Taro.redirectTo({
url: '/pages/index/index'
})
}
})
} else {
Taro.showToast({
title: data.msg,
title: result.msg,
icon: 'error',
duration: 2000
})
}
},
fail: function () {
Taro.showToast({
title: "请求失败",
icon: 'error',
duration: 2000
})
}
})
}

View File

@ -0,0 +1,12 @@
module.exports = {
user: {
role: {
ADMIN: 0,
STAFF: 1,
RESIDENTS_OWNER: 2,
RESIDENTS_MEMBER: 3,
RESIDENTS_TENENT: 4,
VISITOR: 5
}
}
}