| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <template>
- <view>
- <!-- 头像区域 -->
- <view class="avatar-region">
- <view class="flex-items">
- <view class="font32 mar-l-20">
- 头像
- </view>
- <view class="mar-l-auto mar-r-20">
- <u-upload :fileList="fileList" @afterRead="afterRead" name="1" :maxCount="1">
- <view class="flex-items">
- <image class="avatar" :src="user.avatar||'../../static/images/avatar.png'"
- mode="aspectFill">
- </image>
- <uni-icons color="#d0d7df" type="right" size="30"></uni-icons>
- </view>
- </u-upload>
- </view>
- </view>
- </view>
- <!-- 基本信息区域 -->
- <view class="info-region">
- <view class="font-gray mar-l-20 mar-b-30">
- 基本信息
- </view>
- <view class="flex-items mar-b-50">
- <view class="font32 mar-l-20">
- 姓名
- </view>
- <view class="mar-l-auto mar-r-20">
- <view class="flex-items">
- <u-input v-model="user.account" :border="false" placeholder="请输入姓名"></u-input>
- </view>
- </view>
- </view>
- <view class="flex-items mar-b-50">
- <view class="font32 mar-l-20 ">
- 手机号码
- </view>
- <view class="mar-l-auto mar-r-20">
- <view class="flex-items">
- <u-input v-model="user.phone" :border="false" placeholder="请输入手机号码" type="number"></u-input>
- </view>
- </view>
- </view>
- <view class="flex-items mar-b-50">
- <view class="font32 mar-l-20 ">
- 公司名称
- </view>
- <view class="mar-l-auto mar-r-20 select-container">
- <view class="flex-items">
- <uni-data-select v-model="user.companyId" :localdata="companyOptions" :clear="false"
- class="custom-select"></uni-data-select>
- </view>
- </view>
- </view>
- <view class="flex-items mar-b-50">
- <view class="font32 mar-l-20 ">
- 部门
- </view>
- <view class="mar-l-auto mar-r-20 select-container">
- <view class="flex-items">
- <uni-data-select v-model="user.departmentId" :localdata="departmentOptions" :clear="false"
- class="custom-select"></uni-data-select>
- </view>
- </view>
- </view>
- </view>
- <view class="button-container">
- <button @click="handleSave" class="save-button">
- 保存
- </button>
- <button @click="handlerLogout" class="logout-button">
- 退出登录
- </button>
- </view>
- </view>
- </template>
- <script>
- import {
- memberDetail,
- memberUpdate
- } from '@/config/api';
- import {
- mapMutations,
- mapActions,
- mapGetters
- } from 'vuex';
- import {
- UPLOAD_URL
- } from '@/common/config.js'
- export default {
- data() {
- return {
- fileList: [],
- user: {},
- token: "",
- companyOptions: [{
- value: 1,
- text: '科技有限公司'
- },
- {
- value: 2,
- text: '网络科技公司'
- },
- {
- value: 3,
- text: '软件开发公司'
- }
- ],
- departmentOptions: [{
- value: 1,
- text: '技术部'
- },
- {
- value: 2,
- text: '产品部'
- },
- {
- value: 3,
- text: '运营部'
- },
- {
- value: 4,
- text: '市场部'
- }
- ]
- };
- },
- computed: {
- ...mapGetters(['userInfo'])
- },
- onLoad() {
- this.token = uni.getStorageSync('access_token')
- },
- onShow() {
- this.detail()
- console.log(this.user)
- },
- methods: {
- ...mapActions(['logout']),
- handlerLogout() {
- this.logout()
- uni.$u.toast("退出登录")
- uni.navigateBack({
- delta: 1 // delta 表示返回的页面数,1 表示返回上一页
- });
- },
- // 新增图片
- async afterRead(event) {
- // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file)
- console.log(lists, "list")
- let fileListLen = this.fileList.length
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i].thumb)
- this.user.avatar = result.data.link
- let item = this.fileList[fileListLen]
- }
- memberUpdate(this.user)
- },
- uploadFilePromise(url) {
- return new Promise((resolve, reject) => {
- let a = uni.uploadFile({
- url: UPLOAD_URL,
- filePath: url,
- header: {
- "Blade-Auth": this.token
- },
- name: 'file',
- formData: {
- user: 'test'
- },
- success: (res) => {
- resolve(JSON.parse(res.data))
- }
- });
- })
- },
- async detail() {
- const data = await memberDetail()
- if (data.code == 200) {
- this.user = data.data
- uni.setStorageSync('user', this.user)
- }
- },
- async handleSave() {
- try {
- const result = await memberUpdate(this.user)
- console.log(result, "12")
- if (result.code === 200) {
- console.log("12")
- // 重新获取最新数据
- await this.detail()
- uni.showToast({
- title: '保存成功',
- icon: 'success',
- duration: 2000
- });
- } else {
- uni.showToast({
- title: '保存失败',
- icon: 'success',
- duration: 2000
- });
- }
- } catch (error) {
- uni.showToast({
- title: '保存失败',
- icon: 'success',
- duration: 2000
- });
- console.error('Save error:', error)
- }
- },
- },
- };
- </script>
- <style>
- .avatar-region {
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
- border-radius: 40rpx;
- width: 700rpx;
- height: auto;
- padding-bottom: 30rpx;
- padding-top: 30rpx;
- background-color: white;
- margin-top: 30rpx;
- margin-bottom: 30rpx;
- margin-left: 25rpx;
- }
- .info-region {
- box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
- border-radius: 40rpx;
- width: 700rpx;
- height: auto;
- padding-bottom: 30rpx;
- padding-top: 30rpx;
- background-color: white;
- margin-top: 30rpx;
- margin-bottom: 30rpx;
- margin-left: 25rpx;
- }
- .avatar {
- width: 130rpx;
- height: 130rpx;
- border-radius: 50%;
- overflow: hidden;
- }
- .button-container {
- padding: 0 32rpx;
- margin-top: 60rpx;
- }
- .save-button {
- width: 100%;
- height: 88rpx;
- background: #2979ff;
- border-radius: 44rpx;
- font-size: 32rpx;
- color: #FFFFFF;
- margin-bottom: 30rpx;
- }
- .logout-button {
- width: 100%;
- height: 88rpx;
- background: #FF4748;
- border-radius: 44rpx;
- font-size: 32rpx;
- color: #FFFFFF;
- }
- .select-container {
- width: 400rpx;
- }
- /* 自定义下拉框样式 */
- .custom-select {
- width: 100% !important;
- }
- /* 确保下拉框内容可以完整显示 */
- :deep(.uni-select) {
- width: 100% !important;
- }
- :deep(.uni-select__input-box) {
- width: 100% !important;
- padding-right: 30rpx !important;
- }
- :deep(.uni-select__input-text) {
- flex: 1;
- }
- :deep(.uni-select__selector) {
- width: 100% !important;
- }
- </style>
|