123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <view class="updateStyle">
- <view>
- <view>
- <view>
- <u--text text="设置头像" size="20"></u--text>
- <u--text style="padding: 10px;" color="#b9b9b9" text="请上传正方形图片" size="12"></u--text>
- </view>
- <view class="uploadImgView">
- <u-upload :fileList="fileList" @afterRead="afterRead" name="1" :maxCount="1" width='100'
- height='100' deletable uploadText="请上传正方形图片" :capture="['album']">
- <image :src="this.$BASE_URL + defaultAvatarSrc" style="width:100px;height:100px;">
- </image>
- </u-upload>
- </view>
- <!-- <view class="subBotton">
- <u-button text="保存"></u-button>
- </view> -->
- </view>
- </view>
- <view class="xgPwdStyle">
- <view>
- <view>
- <u--text text="修改密码" size="20"></u--text>
- </view>
- <view style="margin-top: 20px;">
- <u--input class="pwdInput" placeholder="旧密码" type="password" v-model="from.oldPassword"
- :maxlength="8" border="surround"></u--input>
- <u--input class="pwdInput" placeholder="新密码" type="password" v-model="from.newPassword"
- :maxlength="8" border="surround"></u--input>
- <u--input class="pwdInput" placeholder="确认新密码" type="password" v-model="newPassword1" :maxlength="8"
- border="surround">
- </u--input>
- </view>
- <view class="subBotton">
- <u-button color="rgb(55,186,189)" text="修改" @click="doUpdatePwd()"></u-button>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import subscription from '../../../pageA/msg/subscription.vue'
- export default {
- components: {
- subscription
- },
- data() {
- return {
- scrollable: true,
- fileList: [],
- from: {
- oldPassword: '',
- newPassword: ''
- },
- newPassword1: '',
- defaultAvatarSrc: ''
- }
- },
- created() {
- //console.log("create")
- this.defaultAvatarSrc = uni.getStorageSync('userInfo').avatar
- },
- methods: {
- // 删除图片
- deletePic(event) {
- this.fileList.splice(event.index, 1)
- },
- // 新增图片
- async afterRead(event) {
- // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file)
- lists.map((item) => {
- this.fileList.push({
- ...item,
- status: 'uploading',
- message: '上传中'
- })
- })
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i].thumb)
- let item = this.fileList[0]
- this.fileList.splice(0, 1, Object.assign(item, {
- status: 'success',
- message: '',
- url: result
- }))
- }
- //console.log(this.fileList)
- uni.getImageInfo({
- src: lists[0].url,
- success: (res) => {
- //console.log(res, "获取图片信息")
- uni.showToast({
- duration: 1500,
- icon: 'checkmark',
- title: '头像已更新'
- });
- },
- fail: (err) => {
- console.log(err)
- }
- });
- },
- uploadFilePromise(url) {
- return new Promise((resolve, reject) => {
- uni.showToast({
- duration: 1500,
- icon: 'none',
- title: this.$BASE_URL
- });
- let a = uni.uploadFile({
- url: this.$BASE_URL + '/system/user/profile/avatar',
- filePath: url,
- name: 'avatarfile',
- header: {
- Authorization: "Bearer " + uni.getStorageSync('token')
- },
- success: (res) => {
- resolve(res.imgUrl)
- }
- });
- })
- },
- async doUpdatePwd() {
- if (this.from.newPassword.length < 6) {
- uni.showToast({
- duration: 1500,
- icon: 'none',
- title: '新密码至少需要 6 位数'
- });
- return;
- }
- if (!this.from.newPassword === this.newPassword1) {
- uni.showToast({
- duration: 1500,
- icon: 'none',
- title: '2 次新密码不一致'
- });
- return;
- }
- // 发送请求
- const {
- data: res
- } = await this.$httpRequest({
- url: '/system/user/profile/updatePwd?oldPassword=' + this.from.oldPassword +
- "&newPassword=" + this.from.newPassword,
- method: 'put'
- });
- if (res.code === 200) {
- uni.showToast({
- duration: 1500,
- icon: 'checkmark',
- title: '密码已更新'
- });
- this.from = {}
- this.newPassword1 = ''
- }else{
- uni.showToast({
- duration: 1500,
- icon: 'none',
- title: res.msg
- });
- }
- uni.hideLoading()
- }
- }
- }
- </script>
- <style scoped>
- .uploadImgView {
- padding-top: 10px;
- margin: 0 auto;
- background-color: #efefef;
- padding: 10px;
- border-radius: 10px;
- width: 100px;
- height: 100px;
- }
- .updateStyle {
- padding: 20px;
- }
- .xgPwdStyle {
- margin-top: 30px;
- }
- .pwdInput {
- margin-bottom: 20px;
- width: 100%;
- }
- .subBotton {
- padding-top: 30px;
- margin: 0 auto;
- width: 150px;
- }
- </style>
|