my.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="user" hover-class="navigator-hover" @click="popupShow = true">
  3. <view class="profile-photo">
  4. <up-image :show-loading="true" :src="user.profilePhoto" width="120rpx" height="120rpx" />
  5. </view>
  6. <view class="user-info">
  7. <view class="user-name">{{ user.name }}</view>
  8. <view class="user-phone">{{ user.phonenumber }}</view>
  9. </view>
  10. <view class="iconfont icon-shezhi" />
  11. </view>
  12. <!-- <view class="change-user" style="padding: 20rpx;">
  13. <navigator class="row" url="/pages/index/changePassword">
  14. <view class="label" style="padding: 10rpx;box-sizing: border-box;">
  15. <text class="iconfont icon-mima" style="margin-right: 10rpx;" />
  16. 修改登录密码
  17. </view>
  18. <view class="value">
  19. <view class="iconfont icon-a-wodetiaozhuan" />
  20. </view>
  21. </navigator>
  22. </view> -->
  23. <up-popup :show="popupShow" mode="right" :customStyle="{
  24. width: '80vw',
  25. padding: '0 20rpx',
  26. background: '#F7F7FF'
  27. }" zIndex="99" @close="close" @open="open">
  28. <view class="change-user">
  29. <view class="title">
  30. 账号信息
  31. </view>
  32. <view class="row" v-if="headportraitLoading">
  33. <view class="label">
  34. 点击更换头像
  35. </view>
  36. <view class="value">
  37. <view class="profilePhoto">
  38. <up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
  39. <view class="loading">
  40. <up-loading-icon mode="semicircle" />
  41. </view>
  42. </view>
  43. <view class="iconfont icon-a-wodetiaozhuan" />
  44. </view>
  45. </view>
  46. <My_upload ref="upload" custom maxCount="1" @uploadCallback="uploadCallback"
  47. @startUploading="startUploading">
  48. <view class="row" v-if="!headportraitLoading" style="width: calc(80vw);" hover-class="navigator-hover">
  49. <view class="label">
  50. 点击更换头像
  51. </view>
  52. <view class="value">
  53. <view class="profilePhoto">
  54. <up-image :show-loading="true" :src="user.profilePhoto" width="80rpx" height="80rpx" />
  55. </view>
  56. <view class="iconfont icon-a-wodetiaozhuan" />
  57. </view>
  58. </view>
  59. </My_upload>
  60. <view class="row" hover-class="navigator-hover" @click="modalShow = true">
  61. <view class="label">
  62. 用户昵称
  63. </view>
  64. <view class="value">
  65. {{ user.name }}
  66. <view class="iconfont icon-a-wodetiaozhuan" />
  67. </view>
  68. </view>
  69. <view class="row">
  70. <view class="label">
  71. 手机号码
  72. </view>
  73. <view class="value">
  74. {{ user.phonenumber }}
  75. </view>
  76. </view>
  77. </view>
  78. </up-popup>
  79. <view class="but">
  80. <up-button type="primary" shape="circle" size="large" color="#3874F6" text="退出登录" @tap="logOut" />
  81. </view>
  82. <up-modal :show="modalShow" title="修改昵称" showCancelButton @confirm="confirm" @cancel="modalShow = false"
  83. ref="uModal" :asyncClose="true">
  84. <up-input :placeholder="user.name" border="surround" v-model="userName"></up-input>
  85. </up-modal>
  86. </template>
  87. <script setup>
  88. import { ref, reactive, getCurrentInstance } from 'vue'
  89. const { $Http } = getCurrentInstance().proxy;
  90. import { onLoad } from '@dcloudio/uni-app';
  91. let user = reactive({
  92. name: '',
  93. phonenumber: '',
  94. profilePhoto: "",
  95. attinfos: []
  96. });
  97. onLoad(() => {
  98. getUserMsg()
  99. const userInfo = uni.getStorageSync('userMsg')
  100. user.name = userInfo.name;
  101. user.phonenumber = userInfo.phonenumber;
  102. user.attinfos = userInfo.attinfos;
  103. user.profilePhoto = userInfo.profilePhoto || '/static/image/user.png';
  104. });
  105. let popupShow = ref(false),
  106. headportraitLoading = ref(false);
  107. function close() {
  108. popupShow.value = false
  109. }
  110. let uModal = ref(null),
  111. modalShow = ref(false),
  112. userName = ref('');
  113. function confirm() {
  114. console.log('修改昵称', userName.value);
  115. if (userName.value.trim() == '') {
  116. modalShow.value = false;
  117. return uni.showToast({
  118. title: '昵称不能为空',
  119. icon: 'none'
  120. })
  121. }
  122. $Http.basic({
  123. "classname": "common.usercenter.usercenter",
  124. "method": "updateUserMsg",
  125. "content": {
  126. "name": userName.value,
  127. "phonenumber": user.phonenumber,
  128. }
  129. }).then(res => {
  130. console.log(res)
  131. uni.showToast({
  132. title: res.code == 1 ? '修改成功' : res.msg,
  133. icon: 'none'
  134. })
  135. modalShow.value = false;
  136. if (res.code == 1) {
  137. userName.value = '';
  138. getUserMsg();
  139. }
  140. })
  141. }
  142. // 更换头像
  143. let upload = ref(null);
  144. function startUploading(e) {
  145. headportraitLoading.value = true;
  146. }
  147. function uploadCallback({ attachmentids, fileList }) {
  148. if (fileList.pop().usetype == 'headportrait') return;
  149. $Http.basic({
  150. "classname": "system.attachment.Attachment",
  151. "method": "createFileLink",
  152. content: {
  153. ownertable: "sys_users",
  154. ownerid: uni.getStorageSync('userMsg').userid,
  155. usetype: 'headportrait',
  156. attachmentids,
  157. siteid: uni.getStorageSync("userMsg").siteid
  158. }
  159. }).then(res => {
  160. console.log('跟进记录绑定附件', res)
  161. if (res.code != '1') return uni.showToast({
  162. title: res.msg,
  163. icon: "none"
  164. })
  165. upload.value.deleteFile(user.attinfos.filter(v => v.usetype == 'headportrait')).then(res1 => {
  166. if (res1) {
  167. getUserMsg();
  168. setTimeout(() => {
  169. uni.showToast({
  170. title: '头像更换成功',
  171. icon: 'none'
  172. });
  173. }, 100);
  174. }
  175. })
  176. })
  177. }
  178. function getUserMsg() {
  179. $Http.basic({
  180. "classname": "common.usercenter.usercenter",
  181. "method": "queryUserMsg",
  182. "content": { "nocache": true }
  183. }).then(res => {
  184. console.log("res", res);
  185. if (res.code == 1) {
  186. user.name = res.data.name;
  187. user.phonenumber = res.data.phonenumber;
  188. user.attinfos = res.data.attinfos;
  189. headportraitLoading.value = false;
  190. const headportrait = res.data.attinfos.find(v => v.usetype == 'headportrait');
  191. user.profilePhoto = headportrait ? $Http.getSpecifiedImage(headportrait) : user.profilePhoto;
  192. const userMsg = uni.getStorageSync('userMsg')
  193. uni.setStorageSync('userMsg', Object.assign(userMsg, user))
  194. }
  195. })
  196. }
  197. function logOut() {
  198. console.log('退出登录');
  199. uni.showModal({
  200. title: '提示',
  201. content: '是否确定退出登录?',
  202. success: function ({ confirm }) {
  203. if (confirm) {
  204. $Http.logout();
  205. uni.removeStorageSync('userMsg');
  206. uni.reLaunch({
  207. url: '/pages/login/login',
  208. success: () => {
  209. uni.showToast({
  210. title: '退出登录成功',
  211. icon: 'none'
  212. });
  213. }
  214. });
  215. }
  216. }
  217. });
  218. }
  219. </script>
  220. <style lang="less" scoped>
  221. .user {
  222. display: flex;
  223. align-items: center;
  224. width: 100%;
  225. background-color: #fff;
  226. box-sizing: border-box;
  227. padding: 40rpx;
  228. .profile-photo {
  229. width: 120rpx;
  230. height: 120rpx;
  231. border-radius: 50%;
  232. overflow: hidden;
  233. }
  234. .user-info {
  235. flex: 1;
  236. margin-left: 40rpx;
  237. padding-top: 10rpx;
  238. .user-name {
  239. line-height: 42rpx;
  240. font-family: Microsoft YaHei, Microsoft YaHei;
  241. font-size: 32rpx;
  242. color: #333333;
  243. }
  244. .user-phone {
  245. line-height: 38rpx;
  246. font-family: Microsoft YaHei, Microsoft YaHei;
  247. font-size: 28rpx;
  248. color: #999999;
  249. margin-top: 20rpx;
  250. }
  251. }
  252. }
  253. .change-user {
  254. position: relative;
  255. padding-top: 55px;
  256. box-sizing: border-box;
  257. height: 100%;
  258. .title {
  259. font-size: 28rpx;
  260. color: #333;
  261. margin-bottom: 30rpx;
  262. padding-left: 20rpx;
  263. }
  264. .row {
  265. width: 100%;
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. background: #fff;
  270. padding: 20rpx 30rpx;
  271. border-radius: 16rpx;
  272. box-sizing: border-box;
  273. margin-bottom: 20rpx;
  274. .label {
  275. font-size: 28rpx;
  276. color: #666;
  277. flex-shrink: 0;
  278. margin-right: 20rpx;
  279. }
  280. .value {
  281. display: flex;
  282. align-items: center;
  283. .profilePhoto {
  284. position: relative;
  285. width: 80rpx;
  286. height: 80rpx;
  287. border-radius: 50%;
  288. overflow: hidden;
  289. .loading {
  290. position: absolute;
  291. top: 0;
  292. left: 0;
  293. width: 100%;
  294. height: 100%;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. background: rgba(0, 0, 0, 0.09);
  299. z-index: 1;
  300. }
  301. }
  302. .iconfont {
  303. font-size: 28rpx;
  304. color: #999;
  305. margin-top: 5rpx;
  306. }
  307. }
  308. }
  309. }
  310. .but {
  311. box-sizing: border-box;
  312. width: 100vw;
  313. position: fixed;
  314. bottom: 16%;
  315. padding: 0 60rpx;
  316. }
  317. </style>