| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <template>
- <view class="container">
- <view class="body">
- <!-- 个人头像区域 -->
- <view class="body_box">
- 个人头像
- <view class="box_right" @click="handleClickPhoto">
- <img mode="aspectFill" class="img" :src="imgUrl || '../../static/my/portrait.png'" />
- <img class="img2" src="../../static/my/right.png" />
- </view>
- </view>
- <!-- 账号名区域 -->
- <view class="body_box" @click="handleClickName">
- 账号名
- <view class="box_right">
- <view class="msg">{{ name }}</view>
- <img class="img2" src="../../static/my/right.png" />
- </view>
- </view>
- <!-- ID区域 -->
- <view class="body_box">
- ID
- <view class="box_right">
- <view class="msg">{{ id }}</view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { cos } from '@/util/cos.js'
- export default {
- data() {
- return {
- // 头像
- imgUrl: '',
- // 账号名
- name: '',
- //用户id
- id: ''
- }
- },
- onLoad() {
- this.getUserInfo()
- },
- methods: {
- getUserInfo() {
- let userInfo = uni.getStorageSync('userInfo')
- this.name = userInfo.user_name
- this.imgUrl = userInfo.headPhoto
- this.id = userInfo.id
- },
- // 点击头像图片回调
- handleClickPhoto() {
- uni.showActionSheet({
- itemList: ['更换头像'],
- success: (res) => {
- if (res.tapIndex === 0) {
- this.changeImg()
- }
- }
- })
- },
- // 更换头像回调
- changeImg() {
- uni.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album'], //从相册选择
- success: (res) => {
- let filePath = res.tempFiles[0].path
- let Key = filePath.substr(filePath.lastIndexOf('/') + 1)
- cos.postObject(
- {
- Bucket: 'jinganminsu-1320402385',
- Region: 'ap-nanjing',
- Key: Key,
- FilePath: filePath,
- onProgress: (info) => {
- // console.log(info)
- }
- },
- async (err, data) => {
- if (err) {
- console.log('上传失败', err)
- } else {
- // console.log('上传成功', data)
- this.imgUrl = 'https://' + data.Location
- const result = await this.$myRequest({
- url: '/mhotel/ampupdateUserInfo.action',
- data: {
- userId: this.id,
- userName: this.name,
- headPhoto: this.imgUrl
- }
- })
- if (result.code === 200) {
- uni.showToast({
- title: '头像修改成功',
- icon: 'success',
- mask: true
- })
- setTimeout(() => {
- this.getUser()
- }, 1500)
- }
- }
- }
- )
- }
- })
- },
- // 点击账号名回调
- handleClickName() {
- uni.showActionSheet({
- itemList: ['修改账号名'],
- success: (res) => {
- if (res.tapIndex === 0) {
- this.changeName()
- }
- }
- })
- },
- // 修改账号名回调
- changeName() {
- uni.showModal({
- title: '请输入账号名',
- editable: true,
- success: async (res) => {
- if (res.confirm) {
- if (!res.content) {
- uni.showToast({
- title: '账号名不能为空',
- icon: 'none'
- })
- setTimeout(() => {
- this.changeName()
- }, 1500)
- } else if (res.content.length > 8) {
- uni.showToast({
- title: '账号名最多8位',
- icon: 'none'
- })
- setTimeout(() => {
- this.changeName()
- }, 1500)
- } else {
- const result = await this.$myRequest({
- url: '/mhotel/ampupdateUserInfo.action',
- data: {
- userId: this.id,
- userName: res.content,
- headPhoto: this.imgUrl
- }
- })
- if (result.code === 200) {
- uni.showToast({
- title: '账号修改成功',
- icon: 'success',
- mask: true
- })
- setTimeout(() => {
- this.getUser()
- }, 1500)
- }
- }
- }
- }
- })
- },
- //获取个人信息
- async getUser() {
- const res = await this.$myRequest({
- url: '/mhotel/ampqueryUsersById.action',
- data: {
- userId: uni.getStorageSync('userInfo').id
- }
- })
- if (res.code === 200) {
- this.name = res.data.user_name
- this.imgUrl = res.data.headPhoto
- uni.setStorageSync('userInfo', res.data)
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- display: flex;
- flex-direction: column;
- min-height: 100vh;
- background-color: #ebeced;
- .body {
- box-sizing: border-box;
- margin-top: 20rpx;
- padding: 0 30rpx;
- height: calc(100vh - 20rpx);
- background-color: #fff;
- .body_box {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 100rpx;
- font-size: 28rpx;
- border-bottom: 1rpx solid #e6e6e6;
- .box_right {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- height: 100rpx;
- .img {
- width: 64rpx;
- height: 64rpx;
- border-radius: 50%;
- }
- .img2 {
- margin-left: 7rpx;
- width: 47rpx;
- height: 47rpx;
- }
- .msg {
- color: #808080;
- }
- }
- }
- }
- }
- </style>
|