index.vue
3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-22 12:19:33
* @FilePath: /meihuaApp/src/pages/myInfo/index.vue
* @Description: 我的信息页面
-->
<template>
<view class="my-info-page">
<view class="avatar" @tap="uploadImg">
<nut-avatar size="100">
<img :src="avatarUrl ? avatarUrl : avatar" style="border-radius: 50%;"/>
</nut-avatar>
<view class="edit">编辑</view>
</view>
<view class="info-name">
<nut-row type="flex" justify="center" align="center">
<nut-col span="4">姓名</nut-col>
<nut-col span="18">
<view class="wrapper">
<nut-input v-model="username" placeholder="请输入姓名" :border="false" />
</view>
</nut-col>
<nut-col span="2">
</nut-col>
</nut-row>
</view>
<view class="info-tel">
<nut-row type="flex" justify="center" align="center">
<nut-col span="4">电话</nut-col>
<nut-col span="18">
<view class="wrapper">
<nut-input v-model="tel" placeholder="请输入电话" :border="false" type="number" max-length="11" disabled />
</view>
</nut-col>
<nut-col span="2">
<IconFont name="edit" @tap="goToEdit"></IconFont>
</nut-col>
</nut-row>
</view>
<view class="save-btn">
<nut-button @tap="save" block color="#6A4925" size="large">
<text>保 存</text>
</nut-button>
</view>
</view>
</template>
<script setup>
import Taro from '@tarojs/taro'
import { IconFont } from '@nutui/icons-vue-taro';
import { ref, onMounted } from "vue";
import avatar from '@/assets/images/avatar.png'
import { showMyInfoAPI, saveCustomerInfoAPI } from '@/api/index'
import BASE_URL from '@/utils/config';
const username = ref('');
const tel = ref('');
const avatarUrl = ref('');
onMounted(async () => {
const { code, data } = await showMyInfoAPI();
if (code) {
username.value = data.wxapp_user_name ? data.wxapp_user_name : '默认用户';
tel.value = data.wxapp_user_phone;
avatarUrl.value = data.wxapp_user_avatar;
}
})
const goToEdit = () => {
Taro.navigateTo({
url: '/pages/bind/index'
})
};
const uploadImg = () => {
Taro.chooseImage({
count: 1,
success: (res) => {
const tempFilePaths = res.tempFilePaths[0];
Taro.uploadFile({
url: BASE_URL + '/admin/?m=srv&a=upload',
filePath: tempFilePaths,
name: 'file',
header: {
'content-type': 'multipart/form-data',
},
success: function (res) {
let upload_data = JSON.parse(res.data);
Taro.hideLoading({
success: () => {
if (res.statusCode === 200) {
avatarUrl.value = upload_data.data.src;
} else {
Taro.showToast({
icon: 'error',
title: '服务器错误,稍后重试!',
mask: true
})
}
},
});
}
});
}
})
}
// const isValidTel = (tel) => {
// return /^1\d{10}$/.test(tel);
// }
const save = async () => {
if (!username.value) {
Taro.showToast({
title: '请检查用户名输入',
icon: 'error',
duration: 2000
});
return;
} else {
const { code, data } = await saveCustomerInfoAPI({ name: username.value, avatar: avatarUrl.value });
if (code) {
Taro.showToast({
title: '保存成功',
icon: 'success',
duration: 1000,
success: () => {
setTimeout(() => {
Taro.reLaunch({
url: '/pages/my/index'
})
}, 1000);
}
});
}
}
}
</script>
<script>
import "./index.less";
import mixin from '@/utils/mixin';
export default {
name: "myInfoPage",
mixins: [mixin.init],
};
</script>