Browse Source

编辑用户信息

master
parent
commit
6afaaae3bc
  1. 9
      .gitignore
  2. 2
      App.vue
  3. 12
      api/system/dict.js
  4. 2
      api/system/user.js
  5. 3
      main.js
  6. 2
      manifest.json
  7. 30
      pages/login.vue
  8. 47
      permission.js
  9. 18
      store/modules/user.js
  10. 138
      sub/owner/edit.vue
  11. 5
      uni_modules/s-components/s-header/index.vue
  12. 8
      utils/dict.js
  13. 2
      utils/request.js
  14. 18
      utils/upload.js

9
.gitignore vendored

@ -1,17 +1,8 @@
######################################################################
# Build Tools
/unpackage/* /unpackage/*
/node_modules/* /node_modules/*
######################################################################
# Development Tools
/.idea/* /.idea/*
/.vscode/* /.vscode/*
/.hbuilderx/* /.hbuilderx/*
package-lock.json package-lock.json
yarn.lock yarn.lock
/unpackage/

2
App.vue

@ -17,7 +17,7 @@ export default {
// //
this.initConfig() this.initConfig()
// //
// this.checkLogin() this.checkLogin()
}, },
initConfig() { initConfig() {
this.globalData.config = config this.globalData.config = config

12
api/system/dict.js

@ -0,0 +1,12 @@
import request from '@/utils/request'
/**
* 获取字典
*/
export function getDictBatchByType(params) {
return request({
url: `/system/dict-data/lists_dict_type`,
method: 'GET',
params
})
}

2
api/system/user.js

@ -34,7 +34,7 @@ export function updateUserProfile(data) {
// 用户头像上传 // 用户头像上传
export function uploadAvatar(data) { export function uploadAvatar(data) {
return upload({ return upload({
url: '/system/user/profile/update-avatar', url: '/admin-api/system/user/profile/update-avatar',
method: 'PUT', method: 'PUT',
name: data.name, name: data.name,
filePath: data.filePath filePath: data.filePath

3
main.js

@ -3,7 +3,7 @@ import App from './App'
import store from './store' // store import store from './store' // store
import plugins from './plugins' // plugins import plugins from './plugins' // plugins
import './permission' // permission import './permission' // permission
import * as dict from '@/utils/dict.js'
// 引入uView // 引入uView
import uView from '@/uni_modules/uview-ui' import uView from '@/uni_modules/uview-ui'
@ -14,6 +14,7 @@ Vue.config.productionTip = false
// 挂载vuex // 挂载vuex
Vue.prototype.$store = store Vue.prototype.$store = store
Vue.prototype.$dict = dict
App.mpType = 'app' App.mpType = 'app'

2
manifest.json

@ -3,7 +3,7 @@
"appid": "__UNI__25A9D80", "appid": "__UNI__25A9D80",
"description": "", "description": "",
"versionName": "1.0.0", "versionName": "1.0.0",
"versionCode": "100", "versionCode": 1,
"transformPx": false, "transformPx": false,
"app-plus": { "app-plus": {
"usingComponents": true, "usingComponents": true,

30
pages/login.vue

@ -1,6 +1,13 @@
<template> <template>
<view class="container"> <view class="container">
<u--image src="/static/favicon.png" width="180px" height="80px" mode="aspectFit" :fade="true" duration="450"></u--image> <u--image
src="/static/favicon.png"
width="180px"
height="80px"
mode="aspectFit"
:fade="true"
duration="450"
></u--image>
<text class="title">智慧生态</text> <text class="title">智慧生态</text>
</view> </view>
</template> </template>
@ -17,7 +24,7 @@ export default {
methods: { methods: {
init() { init() {
uni.login({ uni.login({
success: (res) => { success: res => {
// //
this.$store this.$store
.dispatch('Login', { .dispatch('Login', {
@ -25,8 +32,23 @@ export default {
code: res.code, code: res.code,
state: 'default' state: 'default'
}) })
.then((res) => { .then(() => {
console.log('store.login', res) this.loginSuccess()
})
}
})
},
loginSuccess() {
this.$store.dispatch('GetInfo').then(res => {
const { data } = res
const { user } = data
if (user.mobile) {
uni.switchTab({
url: '/pages/index'
})
} else {
uni.navigateTo({
url: '/sub/owner/edit'
}) })
} }
}) })

47
permission.js

@ -22,27 +22,28 @@ function checkWhite(url) {
// 页面跳转验证拦截器 // 页面跳转验证拦截器
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"] let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => { list.forEach(item => {
// uni.addInterceptor(item, { uni.addInterceptor(item, {
// invoke(to) { invoke(to) {
// if (getAccessToken()) { console.log('addInterceptor', to);
// if (to.path === loginPage) { if (getAccessToken()) {
// uni.reLaunch({ if (to.path === loginPage) {
// url: "/" uni.reLaunch({
// }) url: "/"
// } })
// return true }
// } else { return true
// if (checkWhite(to.url)) { } else {
// return true if (checkWhite(to.url)) {
// } return true
// uni.reLaunch({ }
// url: loginPage uni.reLaunch({
// }) url: loginPage
// return false })
// } return false
// }, }
// fail(err) { },
// console.log(err) fail(err) {
// } console.log(err)
// }) }
})
}) })

18
store/modules/user.js

@ -26,10 +26,6 @@ const user = {
SET_ID: (state, id) => { SET_ID: (state, id) => {
state.id = id state.id = id
}, },
SET_NAME: (state, name) => {
state.name = name
storage.set(constant.name, name)
},
SET_AVATAR: (state, avatar) => { SET_AVATAR: (state, avatar) => {
state.avatar = avatar state.avatar = avatar
storage.set(constant.avatar, avatar) storage.set(constant.avatar, avatar)
@ -51,10 +47,11 @@ const user = {
}, userInfo) { }, userInfo) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login(userInfo).then(res => { login(userInfo).then(res => {
console.log('Login', res); const {
res = res.data; data
} = res
// 设置 token // 设置 token
setToken(res) setToken(data)
resolve() resolve()
}).catch(error => { }).catch(error => {
reject(error) reject(error)
@ -69,19 +66,16 @@ const user = {
}) { }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo().then(res => { getInfo().then(res => {
res = res.data; // 读取 data 数据 const user = res.data.user
const user = res.user
const avatar = (user == null || user.avatar === "" || user.avatar == null) ? require( const avatar = (user == null || user.avatar === "" || user.avatar == null) ? require(
"@/static/images/avatar.jpg") : user.avatar "@/static/images/avatar.jpg") : user.avatar
const nickname = (user == null || user.nickname === "" || user.nickname == null) ? "" : user
.nickname
if (res.roles && res.roles.length > 0) { if (res.roles && res.roles.length > 0) {
commit('SET_ROLES', res.roles) commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions) commit('SET_PERMISSIONS', res.permissions)
} else { } else {
commit('SET_ROLES', ['ROLE_DEFAULT']) commit('SET_ROLES', ['ROLE_DEFAULT'])
} }
commit('SET_NAME', nickname) commit('SET_ID', res.data.user.id)
commit('SET_AVATAR', avatar) commit('SET_AVATAR', avatar)
resolve(res) resolve(res)
}).catch(error => { }).catch(error => {

138
sub/owner/edit.vue

@ -1,26 +1,53 @@
<template> <template>
<cs-page title="编辑个人信息"> <cs-page isCustom>
<template #header>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
<u-icon name="arrow-left" v-if="form.mobile"></u-icon>
<text class="wd-font-800 wd-text-16">编辑个人信息</text>
</view>
</template>
<view class="container"> <view class="container">
<!-- 我的头像 --> <!-- 我的头像 -->
<view class="section wd-flex wd-flex-row wd-justify-between wd-items-center"> <view class="section wd-flex wd-flex-row wd-justify-between wd-items-center">
<text class="wd-font-800">我的头像</text> <text class="wd-font-800">我的头像</text>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px"> <button
<u-avatar src="/static/images/avatar.jpg"></u-avatar> class="wd-flex wd-flex-row wd-items-center avatarBtn"
style="gap: 8px"
type="balanced"
open-type="chooseAvatar"
@chooseavatar="chooseAvatar"
>
<u-avatar :src="form.avatar"></u-avatar>
<u-icon name="arrow-right"></u-icon> <u-icon name="arrow-right"></u-icon>
</view> </button>
</view> </view>
<!-- 真实姓名 --> <!-- 真实姓名 -->
<view class="section wd-flex wd-flex-row wd-justify-between wd-items-center"> <view class="section wd-flex wd-flex-row wd-justify-between wd-items-center">
<text class="wd-font-800">真实姓名</text> <text class="wd-font-800">姓名</text>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px"> <view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
<input class="wd-text-right" type="text" placeholder-class="txt" placeholder="请输入" v-model="form.realName" /> <input
class="wd-text-right"
type="text"
placeholder-class="txt"
placeholder="请输入姓名"
v-model="form.realName"
/>
<u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon> <u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon>
</view> </view>
</view> </view>
<!-- 用户性别 --> <!-- 用户性别 -->
<view class="section wd-flex wd-flex-row wd-justify-between wd-items-center"> <view class="section wd-flex wd-flex-row wd-justify-between wd-items-center">
<text class="wd-font-800">用户性别</text> <text class="wd-font-800">性别</text>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px"> <view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
<input
class="wd-text-right"
type="number"
placeholder-class="txt"
placeholder="请选择性别"
v-model="form.sex"
disabled
@click="showPicker()"
/>
<u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon> <u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon>
</view> </view>
</view> </view>
@ -28,32 +55,107 @@
<view class="section wd-flex wd-flex-row wd-justify-between wd-items-center"> <view class="section wd-flex wd-flex-row wd-justify-between wd-items-center">
<text class="wd-font-800">手机号码</text> <text class="wd-font-800">手机号码</text>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px"> <view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
<input class="wd-text-right" type="number" placeholder-class="txt" placeholder="请输入" v-model="form.mobile" /> <input
class="wd-text-right"
type="number"
placeholder-class="txt"
placeholder="请输入手机号码"
v-model="form.mobile"
/>
<u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon> <u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon>
</view> </view>
</view> </view>
<!-- 所属部门 --> <!-- 所属部门 -->
<view class="section wd-flex wd-flex-row wd-justify-between wd-items-center"> <view class="section wd-flex wd-flex-row wd-justify-between wd-items-center">
<text class="wd-font-800">所属部门</text> <text class="wd-font-800">部门</text>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
<input
class="wd-text-right"
type="number"
placeholder-class="txt"
placeholder="请选择部门"
v-model="form.dept"
disabled
@click="showPicker()"
/>
<u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon>
</view>
</view>
<!-- 身份 -->
<view class="section wd-flex wd-flex-row wd-justify-between wd-items-center" @click="showPicker()">
<text class="wd-font-800">角色</text>
<view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px"> <view class="wd-flex wd-flex-row wd-items-center" style="gap: 8px">
<text v-if="form.userType">{{ $dict.echoDicValue(dictMap.wx_user_type, form.userType) }}</text>
<text class="placeholder" v-else>请选择角色</text>
<u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon> <u-icon name="arrow-right" color="#99A1B7" size="16"></u-icon>
</view> </view>
</view> </view>
<button class="button">提交</button> <button class="button">提交</button>
</view> </view>
<u-picker
:show="picker.show"
:columns="picker.columns"
@cancel="closePicker"
closeOnClickOverlay
@close="closePicker"
></u-picker>
</cs-page> </cs-page>
</template> </template>
<script> <script>
import { getUserProfile, uploadAvatar } from '@/api/system/user.js'
import { getDictBatchByType } from '@/api/system/dict.js'
export default { export default {
data() { data() {
return { return {
dictMap: {},
form: { form: {
avatar: undefined, avatar: undefined,
realName: undefined, realName: undefined,
mobile: undefined, mobile: undefined,
department: undefined department: undefined,
sex: undefined
},
picker: {
show: false,
colums: []
}
}
},
onLoad() {
this.getDict()
},
onShow() {
// this.init()
},
methods: {
showPicker() {
this.picker.show = true
},
closePicker() {
this.picker = {
show: false,
colums: []
}
},
init() {
getUserProfile().then(res => {
this.form = res.data
})
},
getDict() {
getDictBatchByType({ type: ['system_user_sex', 'wx_user_type'].join(',') }).then(res => {
this.dictMap = res.data
})
},
chooseAvatar(e) {
const data = {
name: 'avatarFile',
filePath: e.detail.avatarUrl
} }
uploadAvatar(data).then(res => {
this.init()
})
} }
} }
} }
@ -83,5 +185,21 @@ export default {
line-height: 40px; line-height: 40px;
box-sizing: border-box; box-sizing: border-box;
} }
.placeholder {
color: $uni-text-color-grey;
}
button {
padding-left: 0;
padding-right: 0;
}
.avatarBtn {
background-color: #fff;
flex: 1;
justify-content: flex-end;
&::after {
content: '';
display: none;
}
}
} }
</style> </style>

5
uni_modules/s-components/s-header/index.vue

@ -4,7 +4,7 @@
<view class="operation" v-if="isCustom"> <view class="operation" v-if="isCustom">
<slot></slot> <slot></slot>
</view> </view>
<view class="" v-else> <view v-else>
<view class="operation" v-if="isTab"> <view class="operation" v-if="isTab">
<text class="title">{{ title }}</text> <text class="title">{{ title }}</text>
</view> </view>
@ -50,10 +50,11 @@ export default {
background-color: #fff; background-color: #fff;
box-shadow: 0 1px 2px 1px $cs-shadow-color; box-shadow: 0 1px 2px 1px $cs-shadow-color;
.fit-content { .fit-content {
height: 8vh; height: 6vh;
} }
.operation { .operation {
padding: 5px 10px; padding: 5px 10px;
padding-bottom: 15px;
.title { .title {
color: #000; color: #000;
} }

8
utils/dict.js

@ -0,0 +1,8 @@
/**
* 回显字典值
* @param {Object} dict
* @param {Object} value
*/
export function echoDicValue(dict, value) {
return dict.find(d => d.value == value.toString()).label || ''
}

2
utils/request.js

@ -63,8 +63,6 @@ const request = config => {
} else if (code !== 200) { } else if (code !== 200) {
toast(msg) toast(msg)
reject(code) reject(code)
} else {
toast(msg)
} }
resolve(res.data) resolve(res.data)
}) })

18
utils/upload.js

@ -1,8 +1,14 @@
import store from '@/store' import store from '@/store'
import config from '@/config' import config from '@/config'
import { getAccessToken } from '@/utils/auth' import {
getAccessToken
} from '@/utils/auth'
import errorCode from '@/utils/errorCode' import errorCode from '@/utils/errorCode'
import { toast, showConfirm, tansParams } from '@/utils/common' import {
toast,
showConfirm,
tansParams
} from '@/utils/common'
let timeout = 10000 let timeout = 10000
const baseUrl = config.baseUrl const baseUrl = config.baseUrl
@ -41,7 +47,9 @@ const upload = config => {
showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => { showConfirm("登录状态已过期,您可以继续留在该页面,或者重新登录?").then(res => {
if (res.confirm) { if (res.confirm) {
store.dispatch('LogOut').then(res => { store.dispatch('LogOut').then(res => {
uni.reLaunch({ url: '/pages/login/login' }) uni.reLaunch({
url: '/pages/login/login'
})
}) })
} }
}) })
@ -55,7 +63,9 @@ const upload = config => {
} }
}, },
fail: (error) => { fail: (error) => {
let { message } = error let {
message
} = error
if (message == 'Network Error') { if (message == 'Network Error') {
message = '后端接口连接异常' message = '后端接口连接异常'
} else if (message.includes('timeout')) { } else if (message.includes('timeout')) {

Loading…
Cancel
Save