index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="my" :style="{background:'url('+ bannerImage +')'}">
  3. <view><nav-bar title="none" icon="none" background="transparent" border-color="transparent" ></nav-bar></view>
  4. <view class="content">
  5. <view class="news flex jcsb">
  6. <view class="info flex">
  7. <view style="width:128rpx;height:128rpx"><image class="img" :src="avatar || defaultAvatar" @tap="checkImage"></image></view>
  8. <view class="info-text flex-column jcsa">
  9. <view class="info-top flex aic">
  10. <view class="name">{{name}}</view>
  11. <view class="level flex aic">
  12. <re-image imgSrc="/retail/main/ic_chuji.png" width="54" height="60"></re-image>
  13. <view class="level-text">{{lvName}}</view>
  14. </view>
  15. </view>
  16. <view class="phone">{{username}}</view>
  17. </view>
  18. </view>
  19. <view class="right" @click="logOut"><re-image imgSrc="/retail/my/ic_more.png" width="24" height="24" class="more"></re-image></view>
  20. </view>
  21. <view class="menu">
  22. <view class="menu-item item-one">
  23. <view class="item-left flex aic jcsb" @click="toAccount">
  24. <view class="flex aic">
  25. <re-image imgSrc="/retail/my/ic_jilu.png" width="48" height="48"></re-image>
  26. <text>账户充值记录</text>
  27. </view>
  28. <re-image imgSrc="/retail/my/ic_more.png" width="24" height="24"></re-image>
  29. </view>
  30. </view>
  31. <view class="menu-item">
  32. <view class="item-left flex aic jcsb" @click="contact">
  33. <view class="flex aic">
  34. <re-image imgSrc="/retail/my/ic_kefu.png" width="48" height="48"></re-image>
  35. <text>联系客服</text>
  36. </view>
  37. <re-image imgSrc="/retail/my/ic_more.png" width="24" height="24"></re-image>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <u-popup :show="show" @close="close" @open="open" safeAreaInsetBottom :round="8">
  43. <view class="safe-area-inset-bottom">
  44. <view class="login-out" @click="outLogin">退出登录</view>
  45. </view>
  46. </u-popup>
  47. <u-popup :show="isContact" mode="center" @close="close" @open="open" :round="10">
  48. <view class="kefu">
  49. <view class="tips">
  50. <p>长按或截图保存微信二维码</p>
  51. <p>添加好友即可联系客服</p>
  52. </view>
  53. <image class="contact" :src='kefuImg' @longpress="saveImage"></image>
  54. </view>
  55. </u-popup>
  56. </view>
  57. </template>
  58. <script>
  59. import { toRpx } from '@/utils/calculate.js'
  60. import defaultConfig from '@/config/default.js'
  61. import config from '@/config'
  62. import { changeAvatar } from '@/apis/main'
  63. import { getUserInfo } from '@/apis/user'
  64. export default {
  65. components: {},
  66. computed: {
  67. statusBarHeight() {
  68. return this.$store.state.info.systemInfo?.statusBarHeight
  69. },
  70. },
  71. data() {
  72. return {
  73. show:false,
  74. isContact: false,
  75. bannerImage: defaultConfig.ossImgUrl + '/retail/my/img_myBgc.png',
  76. kefuImg: defaultConfig.ossImgUrl + '/retail/my/wxCon.jpg',
  77. defaultAvatar: '../../static/image/img_touxiang.png',
  78. navBarHeight: uni.getStorageSync('navBarHeight'),
  79. lvName: '',
  80. avatar: '',
  81. name:'',
  82. username:'',
  83. accessToken:''
  84. }
  85. },
  86. onShow() {
  87. this.getInfo()
  88. },
  89. methods: {
  90. saveImage(e){
  91. // 获取图片的路径
  92. const imagePath = e.currentTarget.src;
  93. // 使用uni.saveImageToPhotosAlbum保存图片到系统相册
  94. uni.saveImageToPhotosAlbum({
  95. filePath: imagePath,
  96. success() {
  97. uni.showToast({
  98. title: '图片保存成功',
  99. icon: 'success',
  100. duration: 2000
  101. });
  102. },
  103. fail(err) {
  104. console.log('保存失败:', err);
  105. uni.showToast({
  106. title: '图片保存失败',
  107. icon: 'none'
  108. });
  109. }
  110. });
  111. },
  112. outLogin(){
  113. uni.removeStorageSync('accessToken')
  114. uni.removeStorageSync('userInfo')
  115. uni.removeStorageSync('name')
  116. uni.redirectTo({
  117. url: '/pages/login/index'
  118. })
  119. },
  120. // 跳转充值记录
  121. toAccount(){
  122. uni.navigateTo({
  123. url: '/pages/accountRecharge/index'
  124. })
  125. },
  126. // 联系客服
  127. contact(){
  128. this.isContact = true
  129. },
  130. // 获取用户信息
  131. async getInfo(){
  132. const userInfo = await getUserInfo()
  133. if(userInfo){
  134. const { avatar,name,lvName,username } = userInfo
  135. this.avatar = avatar
  136. this.name = name
  137. this.lvName = lvName
  138. this.username = username
  139. }
  140. },
  141. // 切换头像
  142. checkImage() {
  143. var that = this;
  144. that.accessToken = uni.getStorageSync('accessToken')
  145. uni.chooseImage({
  146. count: 1, // 默认9
  147. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  148. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  149. success: function (res) {
  150. // that.avatar = res.tempFilePaths[0];
  151. uni.uploadFile({
  152. url: `${config.baseUrl}/api/file/upload/FileV3`,
  153. filePath: res.tempFilePaths[0],
  154. header:{
  155. // 'Content-Type': 'multipart/form-data',
  156. 'accessToken': that.accessToken
  157. },
  158. formData: {
  159. user: 'test',
  160. },
  161. success: (res) => {
  162. // console.log(res,'res');
  163. let data = JSON.parse(res.data)
  164. that.upAvatar(data.data)
  165. // setTimeout(() => {
  166. // resolve(data.data)
  167. // }, 1000)
  168. }
  169. })
  170. },
  171. fail:err => {
  172. console.error('选择图片失败',err)
  173. }
  174. });
  175. },
  176. // uploadFilePromise(url) {
  177. // return new Promise((resolve, reject) => {
  178. // let a = uni.uploadFile({
  179. // url: `${config.baseUrl}/api/file/upload/FileV3`,
  180. // filePath: url,
  181. // name: 'file',
  182. // header:{
  183. // 'Content-Type': 'multipart/form-data',
  184. // 'accessToken':uni.setStorageSync('accessToken')
  185. // },
  186. // formData: {
  187. // user: 'test',
  188. // },
  189. // success: (res) => {
  190. // console.log(res,'res');
  191. // let data = JSON.parse(res.data)
  192. // setTimeout(() => {
  193. // resolve(data.data)
  194. // }, 1000)
  195. // }
  196. // });
  197. // })
  198. // },
  199. // 更换头像
  200. async upAvatar(avatar) {
  201. uni.showLoading()
  202. await changeAvatar({avatar:avatar})
  203. uni.hideLoading()
  204. uni.setStorageSync('avatar',avatar)
  205. this.avatar = avatar
  206. uni.showToast({
  207. title:'更换成功'
  208. })
  209. },
  210. logOut(){
  211. this.show = true
  212. },
  213. open() {
  214. // console.log('open');
  215. },
  216. close() {
  217. this.show = false
  218. this.isContact = false
  219. // console.log('close');
  220. }
  221. },
  222. mounted() {
  223. },
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .my {
  228. background-repeat: no-repeat !important;
  229. background-size: contain !important;
  230. // background-position: top;
  231. width: 100%;
  232. position: absolute;
  233. top: 0;
  234. bottom: 0;
  235. .content{
  236. padding: 0 32rpx;
  237. .news {
  238. .info {
  239. .img{
  240. flex-shrink: 0;
  241. width: 128rpx;
  242. height: 128rpx;
  243. border-radius: 8rpx;
  244. }
  245. .info-text {
  246. margin: 8rpx 0 20rpx 36rpx;
  247. .info-top {
  248. .name {
  249. font-weight: 500;
  250. font-size: 32rpx;
  251. color: #363531;
  252. }
  253. .level {
  254. margin-left: 12rpx;
  255. .level-text {
  256. width: 105.9rpx;
  257. height: 47rpx;
  258. padding: 0 16rpx 0 26rpx;
  259. background: linear-gradient(130deg, #FFB873 0%, #FEC287 0%, #E69349 100%);
  260. border-radius: 0rpx 18rpx 18rpx 0rpx;
  261. font-weight: 500;
  262. font-size: 24rpx;
  263. color: #FFFFFF;
  264. line-height: 47rpx;
  265. margin-left: -16rpx;
  266. // text-align: left;
  267. }
  268. }
  269. }
  270. }
  271. .phone {
  272. font-weight: 400;
  273. font-size: 28rpx;
  274. color: #363531;
  275. }
  276. }
  277. .right{
  278. flex: 1;
  279. display: flex;
  280. justify-content: flex-end;
  281. .more{
  282. margin-top: 26rpx;
  283. }
  284. }
  285. .news-total {
  286. margin-top: 44rpx;
  287. .item-num {
  288. font-weight: bold;
  289. font-size: 40rpx;
  290. color: #363531;
  291. }
  292. .orange {
  293. color: #FF6400;
  294. }
  295. .item-text {
  296. font-weight: 400;
  297. font-size: 28rpx;
  298. color: #9598A6;
  299. }
  300. }
  301. }
  302. .menu{
  303. margin-top: 32rpx;
  304. background: #fff;
  305. border-radius: 16rpx;
  306. .menu-item{
  307. padding: 32rpx 28rpx 32rpx 24rpx;
  308. .item-left{
  309. text{
  310. margin-left: 20rpx;
  311. }
  312. }
  313. }
  314. .item-one{
  315. border-bottom: 2rpx solid #F0F2F4;
  316. }
  317. }
  318. }
  319. .login-out{
  320. text-align: center;
  321. margin: 40rpx 0;
  322. }
  323. .kefu{
  324. padding: 40rpx 0;
  325. .contact{
  326. flex-shrink: 0;
  327. object-fit: contain;
  328. }
  329. .tips {
  330. margin-top: 40rpx;
  331. // position: fixed;
  332. // top: 30rem;
  333. // left: 0;
  334. // width: 100%;
  335. text-align: center;
  336. font-size: 32rpx;
  337. p{
  338. margin-bottom: 20rpx;
  339. }
  340. }
  341. }
  342. }
  343. </style>