用户请求加密修改
This commit is contained in:
parent
09cd47f480
commit
a3aff7f118
|
|
@ -9,15 +9,7 @@ export function updateUserPwd(data) {
|
|||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 查询用户个人信息
|
||||
export function getUserProfile(data) {
|
||||
return request({
|
||||
url: '/smart-canteen/custInfo/queryCustInfoDetailForApp',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// 查询用户头像
|
||||
export function getUserHeaderPhoto(data) {
|
||||
return request({
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
"base-64": "^1.0.0",
|
||||
"crypto-js": "^4.2.0",
|
||||
"image-tools": "^1.4.0",
|
||||
"js-cookie": "^3.0.5"
|
||||
"js-cookie": "^3.0.5",
|
||||
"sm-crypto": "^0.3.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"postcss-px-to-viewport": "^1.1.1"
|
||||
|
|
|
|||
|
|
@ -126,12 +126,6 @@
|
|||
"navigationBarTitleText": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/mine/info/edit",
|
||||
"style": {
|
||||
"navigationBarTitleText": "编辑资料"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/mine/pwd/index",
|
||||
"style": {
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@
|
|||
<script>
|
||||
import { getWalletBalanceAPI, getOrderQRCodeAPI } from '../api/index/index'
|
||||
import { getInfoNewAPI } from '@/api/login'
|
||||
import { decryptWithSM4 } from '@/utils/sm'
|
||||
import { queryUserInformApi,queryUnreadInformNumApi } from '@/api/mine/index'
|
||||
import { getAdvanceOrderStallApi } from '@/api/advanceOrder/index.js'
|
||||
export default {
|
||||
|
|
@ -259,11 +260,14 @@ export default {
|
|||
},
|
||||
//获取用户信息
|
||||
getUserInfo(){
|
||||
getInfoNewAPI({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(result => {
|
||||
console.log(result)
|
||||
this.userInfo = result.data
|
||||
uni.setStorageSync('openId', result.data.openid,{expires:90})
|
||||
uni.setStorageSync('placeId', result.data.placeId,{expires:90})
|
||||
getInfoNewAPI({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(result => {
|
||||
this.userInfo = result.data;
|
||||
//sm4加密
|
||||
// let jsonStr = decryptWithSM4(result.data.data)
|
||||
// this.userInfo = JSON.parse(jsonStr)
|
||||
console.log(this.userInfo)
|
||||
uni.setStorageSync('openId', this.userInfo.openid,{expires:90})
|
||||
uni.setStorageSync('placeId', this.userInfo.placeId,{expires:90})
|
||||
})
|
||||
},
|
||||
changeSwiper(e) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { getCodeImg,getInfoNewAPI } from '@/api/login'
|
||||
import { getCodeImg } from '@/api/login'
|
||||
import AES from '@/utils/aes'
|
||||
import Cookies from "js-cookie";
|
||||
export default {
|
||||
|
|
@ -175,18 +175,7 @@ export default {
|
|||
},
|
||||
// 登录成功后,处理函数
|
||||
loginSuccess(result) {
|
||||
// 设置用户信息
|
||||
getInfoNewAPI({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(result => {
|
||||
console.log(result)
|
||||
uni.setStorageSync('openId', result.data.openid,{expires:90})
|
||||
uni.setStorageSync('placeId', result.data.placeId,{expires:90})
|
||||
})
|
||||
this.$tab.reLaunch('/pages/system')
|
||||
|
||||
// uni.navigateTo({
|
||||
// url: '/pages/system'
|
||||
// })
|
||||
|
||||
},
|
||||
// 记住密码
|
||||
rememberPassword(e) {
|
||||
|
|
|
|||
|
|
@ -1,129 +0,0 @@
|
|||
<template>
|
||||
<page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
|
||||
<view class="container">
|
||||
<view class="example">
|
||||
<uni-forms ref="form" :model="user" labelWidth="80px">
|
||||
<uni-forms-item label="用户昵称" name="nickName">
|
||||
<uni-easyinput v-model="user.nickName" placeholder="请输入昵称" />
|
||||
</uni-forms-item>
|
||||
<uni-forms-item label="手机号码" name="phonenumber">
|
||||
<uni-easyinput v-model="user.phonenumber" placeholder="请输入手机号码" />
|
||||
</uni-forms-item>
|
||||
<uni-forms-item label="邮箱" name="email">
|
||||
<uni-easyinput v-model="user.email" placeholder="请输入邮箱" />
|
||||
</uni-forms-item>
|
||||
<uni-forms-item label="性别" name="sex" required>
|
||||
<uni-data-checkbox v-model="user.sex" :localdata="sexs" />
|
||||
</uni-forms-item>
|
||||
</uni-forms>
|
||||
<button type="primary" @click="submit">提交</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getUserProfile } from "@/api/system/user"
|
||||
import { updateUserProfile } from "@/api/system/user"
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
fontValue:uni.getStorageSync('fontSize') || 8,
|
||||
user: {
|
||||
nickName: "",
|
||||
phonenumber: "",
|
||||
email: "",
|
||||
sex: ""
|
||||
},
|
||||
sexs: [{
|
||||
text: '男',
|
||||
value: "0"
|
||||
}, {
|
||||
text: '女',
|
||||
value: "1"
|
||||
}],
|
||||
rules: {
|
||||
nickName: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '用户昵称不能为空'
|
||||
}]
|
||||
},
|
||||
phonenumber: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '手机号码不能为空'
|
||||
}, {
|
||||
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
|
||||
errorMessage: '请输入正确的手机号码'
|
||||
}]
|
||||
},
|
||||
email: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '邮箱地址不能为空'
|
||||
}, {
|
||||
format: 'email',
|
||||
errorMessage: '请输入正确的邮箱地址'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getUser()
|
||||
},
|
||||
onReady() {
|
||||
this.$refs.form.setRules(this.rules)
|
||||
},
|
||||
methods: {
|
||||
getUser() {
|
||||
getUserProfile({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(response => {
|
||||
this.user = response.data
|
||||
})
|
||||
},
|
||||
submit(ref) {
|
||||
this.$refs.form.validate().then(res => {
|
||||
updateUserProfile(this.user).then(response => {
|
||||
this.$modal.msgSuccess("修改成功")
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.example {
|
||||
padding: 15px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.segmented-control {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.form-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
<template>
|
||||
<page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
|
||||
<view class="container">
|
||||
<uni-list>
|
||||
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'person-filled'}" title="昵称" :rightText="user.nickName" />
|
||||
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'phone-filled'}" title="手机号码" :rightText="user.phonenumber" />
|
||||
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'email-filled'}" title="邮箱" :rightText="user.email" />
|
||||
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'auth-filled'}" title="岗位" :rightText="postGroup" />
|
||||
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'staff-filled'}" title="角色" :rightText="roleGroup" />
|
||||
<uni-list-item showExtraIcon="true" :extraIcon="{type: 'calendar-filled'}" title="创建日期" :rightText="user.createTime" />
|
||||
</uni-list>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getUserProfile } from "@/api/system/user"
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
fontValue:uni.getStorageSync('fontSize') || 8,
|
||||
user: {},
|
||||
roleGroup: "",
|
||||
postGroup: ""
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getUser()
|
||||
},
|
||||
methods: {
|
||||
getUser() {
|
||||
getUserProfile({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(response => {
|
||||
this.user = response.data
|
||||
this.roleGroup = response.roleGroup
|
||||
this.postGroup = response.postGroup
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
page {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -122,12 +122,13 @@
|
|||
<script>
|
||||
|
||||
import {
|
||||
getUserProfile,
|
||||
getUserHeaderPhoto,
|
||||
uploadAvatar,
|
||||
updateUserProfile,
|
||||
saveUserHeaderPhoto
|
||||
} from "@/api/system/user"
|
||||
import { getInfoNewAPI } from '@/api/login'
|
||||
import { decryptWithSM4 } from '@/utils/sm'
|
||||
import config from '@/config'
|
||||
import { uploadBase64 } from "@/api/upload"
|
||||
import { pathToBase64, base64ToPath } from 'image-tools';
|
||||
|
|
@ -155,8 +156,11 @@
|
|||
},
|
||||
methods: {
|
||||
getUserInfo() {
|
||||
getUserProfile({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(res => {
|
||||
getInfoNewAPI({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(res => {
|
||||
this.userInfo = res.data;
|
||||
//sm4加密
|
||||
// let jsonStr = decryptWithSM4(res.data.data)
|
||||
// this.userInfo = JSON.parse(jsonStr)
|
||||
this.userInfo.sex = this.userInfo.sex-1
|
||||
this.userInfo.sexStr = this.columns[0][this.userInfo.sex]
|
||||
console.log('this.userInfo',this.userInfo)
|
||||
|
|
|
|||
|
|
@ -42,26 +42,16 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import {
|
||||
getUserProfile
|
||||
} from "@/api/system/user"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
fontValue:uni.getStorageSync('fontSize') || 8,
|
||||
currentPhone: ''
|
||||
currentPhone: uni.getStorageSync('mobile')
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getUserInfo()
|
||||
onLoad() {
|
||||
},
|
||||
methods: {
|
||||
getUserInfo() {
|
||||
getUserProfile({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(res => {
|
||||
this.currentPhone = res.data.mobile
|
||||
})
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@
|
|||
<script>
|
||||
|
||||
import { queryFacePhotoApi,uploadPhotoGenCodeForAppApi } from '@/api/mine/index'
|
||||
import { getUserProfile} from "@/api/system/user"
|
||||
import { uploadBase64 } from "@/api/upload"
|
||||
import { pathToBase64, base64ToPath } from 'image-tools';
|
||||
import config from '@/config'
|
||||
|
|
@ -71,22 +70,14 @@
|
|||
},
|
||||
onLoad() {
|
||||
this.getFacePhoto()
|
||||
this.getUserInfo()
|
||||
},
|
||||
methods: {
|
||||
getFacePhoto(){
|
||||
queryFacePhotoApi({"custId":uni.getStorageSync('custId')}).then(res => {
|
||||
console.log(res)
|
||||
this.facePhotoUrl = res.facePhotoUrl
|
||||
|
||||
})
|
||||
},
|
||||
getUserInfo() {
|
||||
getUserProfile({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(res => {
|
||||
this.userInfo = res.data
|
||||
console.log('this.userInfo', this.userInfo)
|
||||
})
|
||||
},
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
},
|
||||
|
|
@ -139,7 +130,6 @@
|
|||
uni.showLoading({
|
||||
title: '上传中...'
|
||||
})
|
||||
console.log(this.faceData)
|
||||
let param = {
|
||||
"custId": uni.getStorageSync('custId'),
|
||||
"openid": uni.getStorageSync('openId'),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
|
||||
<script>
|
||||
import {
|
||||
getUserProfile,
|
||||
updateUserProfile
|
||||
} from "@/api/system/user"
|
||||
|
||||
|
|
@ -51,15 +50,10 @@ export default {
|
|||
return /^1[3-9]\d{9}$/.test(this.phoneNumber)
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getUserInfo()
|
||||
onLoad() {
|
||||
},
|
||||
methods: {
|
||||
getUserInfo() {
|
||||
getUserProfile({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(res => {
|
||||
this.userInfo = res.user
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
|
|
@ -74,18 +68,10 @@ export default {
|
|||
uni.showToast({ title: '请正确输入手机号', icon: 'none' })
|
||||
return
|
||||
}
|
||||
// this.userInfo.phonenumber = this.phoneNumber
|
||||
// updateUserProfile(this.userInfo).then(res => {
|
||||
// uni.showToast({ title: '修改成功', icon: 'success',duration: 2000 });
|
||||
// setTimeout(() => {
|
||||
// uni.navigateBack()
|
||||
// },2000)
|
||||
// })
|
||||
|
||||
// 这里添加获取验证码的逻辑
|
||||
uni.navigateTo({
|
||||
url: `/pages/mine/me/phoneCode?phone=${this.phoneNumber}`
|
||||
})
|
||||
// 这里添加获取验证码的逻辑
|
||||
uni.navigateTo({
|
||||
url: `/pages/mine/me/phoneCode?phone=${this.phoneNumber}`
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
<script>
|
||||
import { getInfoNewAPI } from '@/api/login'
|
||||
import { decryptWithSM4 } from '@/utils/sm'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
|
@ -68,8 +69,10 @@ export default {
|
|||
//获取用户信息
|
||||
getUserInfo(){
|
||||
getInfoNewAPI({'custId':uni.getStorageSync('custId'),"sourceType":7}).then(result => {
|
||||
this.userInfo = result.data
|
||||
console.log(this.userInfo)
|
||||
this.userInfo = result.data;
|
||||
//sm4加密
|
||||
// let jsonStr = decryptWithSM4(result.data.data)
|
||||
// this.userInfo = JSON.parse(jsonStr)
|
||||
})
|
||||
},
|
||||
handleItem(index) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import config from '@/config'
|
||||
import storage from '@/utils/storage'
|
||||
import constant from '@/utils/constant'
|
||||
import { login, logout, getInfo, getInfoNewAPI } from '@/api/login'
|
||||
import { login, logout, getInfo } from '@/api/login'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
import Cookies from "js-cookie";
|
||||
const baseUrl = config.baseUrl
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// SM 配置
|
||||
export const SM_CONFIG = {
|
||||
SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值(16 字节)
|
||||
SM4_KEY:"78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥
|
||||
SM4_SALT:"f555adf6c01d0ab0761e626a2dae34a2",
|
||||
SM2_PUBLIC_KEY: 'your-public-key', // SM2 公钥
|
||||
SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥
|
||||
}
|
||||
// AES 配置
|
||||
export const AES_CONFIG = {
|
||||
AES_KEY: 'zhgd@bonus@zhgd@bonus@1234567890', // AES key值
|
||||
AES_IV: '1234567812345678' // AES 偏移量
|
||||
}
|
||||
|
||||
export function generateUUID() {
|
||||
// 使用当前时间戳和随机数生成一个 UUID
|
||||
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
const r = Math.random() * 16 | 0; // 生成随机数
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8); // 根据 UUID 规范生成相应的值
|
||||
return v.toString(16); // 转换为十六进制
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
// src/utils/encryption.js
|
||||
import { sm2, sm3, sm4 } from 'sm-crypto'
|
||||
// 配置项,例如盐值、SM2 公私钥、SM4 密钥
|
||||
import { SM_CONFIG } from './configure'
|
||||
import SM4 from 'sm-crypto/src/sm4'
|
||||
import { hexToArray } from 'sm-crypto/src/sm2/utils'
|
||||
|
||||
// SM3 哈希
|
||||
export function hashSM3(text) {
|
||||
// 对数据进行哈希计算
|
||||
return sm3(text)
|
||||
}
|
||||
|
||||
// 使用 SM3 进行哈希并加入盐值
|
||||
export function hashWithSM3AndSalt(text) {
|
||||
// 将文本和盐值拼接在一起
|
||||
const textWithSalt = SM_CONFIG.SALT + text
|
||||
// 使用 SM3 进行哈希
|
||||
return hashSM3(textWithSalt)
|
||||
}
|
||||
|
||||
// SM2 加密
|
||||
export function encryptWithSM2(text) {
|
||||
// SM2 公钥加密
|
||||
return sm2.doEncrypt(text, SM_CONFIG.SM2_PUBLIC_KEY)
|
||||
}
|
||||
|
||||
// SM2 解密
|
||||
export function decryptWithSM2(encryptedText) {
|
||||
// SM2 私钥解密
|
||||
return sm2.doDecrypt(encryptedText, SM_CONFIG.SM2_PRIVATE_KEY)
|
||||
}
|
||||
/**
|
||||
* 加密函数
|
||||
* @param {string} plainText
|
||||
* @returns {string} 加密后的密文(Hex 编码格式)
|
||||
*/
|
||||
export function encryptWithSM4(plainText) {
|
||||
return sm4.encrypt(plainText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:SM_CONFIG.SM4_SALT});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解密函数
|
||||
* @param {string} cipherText
|
||||
* @returns {string} 解密后的明文
|
||||
*/
|
||||
export function decryptWithSM4(cipherText){
|
||||
return sm4.decrypt(cipherText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:SM_CONFIG.SM4_SALT});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue