myCenter.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="content">
  3. <view class="banner">
  4. <div class="custom-nav">我的</div>
  5. <div class="user-container">
  6. <view class="avatar">
  7. <image v-if="userAvatar" class="photo" :src="userAvatar" mode="widthFix" @error="userAvatar=defaultAvatar"></image>
  8. <image v-else class="photo" :src="defaultAvatar" mode="widthFix"></image>
  9. </view>
  10. <view class="bottom">
  11. <view class="name">
  12. <text>{{userName}}</text>
  13. </view>
  14. <div class="phone">{{phone}}</div>
  15. </view>
  16. </div>
  17. </view>
  18. <view class="zhcx-table">
  19. <uni-list>
  20. <uni-list-item title="个人资料"
  21. link="navigateTo" rightText="修改"
  22. to="/pages/myCenter/personalData/personalData"
  23. showArrow></uni-list-item>
  24. <uni-list-item title="所属院校"
  25. :rightText="school"
  26. link="navigateTo"
  27. to="/pages/myCenter/personalData/personalData"
  28. showArrow></uni-list-item>
  29. <uni-list-item title="人脸录入" @click="faceRecording" clickable showArrow></uni-list-item>
  30. </uni-list>
  31. </view>
  32. <div class="logoutBt" @click="logout" v-if="isLogin">退出登录</div>
  33. <getPhone ref="getPhone" v-if="!isLogin" showByPlatform />
  34. <view class="faceRecord-box" v-if="cameraModel">
  35. <camera device-position="front" flash="off" @error="error" class="camera"></camera>
  36. <button class="takePhotoBt" type="primary" @click="takePhoto">抓拍</button>
  37. <view>预览</view>
  38. <image class="facePhoto" mode="widthFix" :src="faceSrc"></image>
  39. <div class="camera-submit" @click="cameraSubmit">提交</div>
  40. <div class="camera-submit cancel" @click="cameraCancel">取消</div>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import {logout} from '@/api/user.js'
  46. import getPhone from '@/components/getPhone.vue'
  47. export default{
  48. data(){
  49. return{
  50. defaultAvatar:"/static/components/avatar.png",
  51. userAvatar:"",
  52. userName:"--",
  53. phone:"--",
  54. school:"--",
  55. faceSrc:"",
  56. cameraModel:false,
  57. isLogin:true
  58. }
  59. },
  60. components:{
  61. getPhone
  62. },
  63. onShow() {
  64. this.init();
  65. },
  66. methods:{
  67. initPhoneModal(){
  68. const accountName=uni.getStorageSync('phone')
  69. if(!accountName){
  70. this.isLogin=false
  71. this.$nextTick(()=>{
  72. this.$refs['getPhone'].isAuthorize=false
  73. })
  74. }else{
  75. this.isLogin=true
  76. }
  77. },
  78. init(){
  79. this.initPhoneModal()
  80. let user=uni.getStorageSync('accountInfo');
  81. if(user){
  82. user=JSON.parse(user)
  83. this.userAvatar=user.avatar||this.defaultAvatar;
  84. this.userName=user.name;
  85. }
  86. },
  87. faceRecording(){
  88. this.cameraModel=true;
  89. },
  90. takePhoto(){
  91. const ctx = uni.createCameraContext();
  92. ctx.takePhoto({
  93. quality: 'high',
  94. success: (res) => {
  95. this.faceSrc = res.tempImagePath
  96. }
  97. });
  98. },
  99. cameraSubmit(){
  100. this.cameraModel=false;
  101. this.faceSrc = "";
  102. },
  103. cameraCancel(){
  104. this.cameraModel=false;
  105. this.faceSrc = "";
  106. },
  107. logout(){
  108. uni.showModal({
  109. title:'提示!',
  110. content:"是否要退出登录",
  111. success(res) {
  112. if (res.confirm) {
  113. logout().then(()=>{
  114. uni.clearStorageSync()
  115. uni.switchTab({
  116. url:'/pages/index/index'
  117. })
  118. })
  119. }
  120. }
  121. })
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .content{
  128. position: relative;
  129. .banner{
  130. height: 580upx;
  131. background-image: url('/static/center/bg.png');
  132. background-repeat: no-repeat;
  133. background-size: 100% 100%;
  134. position: relative;
  135. &::after{
  136. position: absolute;
  137. content: "";
  138. display: block;
  139. width: 440rpx;
  140. height: 632rpx;
  141. right: 0;
  142. top: 20px;
  143. background-image:url('/static/center/bgmask.png');
  144. background-repeat: no-repeat;
  145. background-size: 100% 100%;
  146. z-index: 1;
  147. }
  148. .custom-nav{
  149. position: fixed;
  150. text-align: center;
  151. top: 24px;
  152. left: var(--window-left);
  153. right: var(--window-right);
  154. height: 88rpx;
  155. line-height: 88rpx;
  156. z-index: 998;
  157. color: #333333;
  158. background-color: transparent;
  159. font-size: 32rpx;
  160. font-weight: 400;
  161. box-sizing: border-box;
  162. font-family: PingFang SC;
  163. }
  164. .user-container{
  165. &{
  166. display: flex;
  167. justify-content: flex-start;
  168. align-items: center;
  169. position: absolute;
  170. bottom: 190rpx;
  171. left: 40rpx;
  172. }
  173. .avatar{
  174. width: 120rpx;
  175. height: 120rpx;
  176. border-radius: 50%;
  177. display: block;
  178. overflow: hidden;
  179. background: rgba(255,255,255,0.39);
  180. border: 2rpx solid #707070;
  181. .photo{
  182. width: 120rpx;
  183. height: 120rpx;
  184. border-radius: 50%;
  185. }
  186. }
  187. .bottom{
  188. &{
  189. padding-left: 20rpx;
  190. }
  191. .name{
  192. font-size: 36rpx;
  193. font-family: PingFang SC;
  194. font-weight: bold;
  195. line-height: 50rpx;
  196. color: #FFFFFF;
  197. }
  198. .phone{
  199. font-size: 28rpx;
  200. font-family: PingFang SC;
  201. font-weight: 400;
  202. line-height: 40rpx;
  203. color: #FFFFFF;
  204. padding-top: 14rpx;
  205. }
  206. }
  207. }
  208. }
  209. .zhcx-table{
  210. width: 710rpx;
  211. position: absolute;
  212. left: 20rpx;
  213. top: 440rpx;
  214. background-color: #fff;
  215. z-index: 99;
  216. border-radius: 12px;
  217. overflow: hidden;
  218. }
  219. .logoutBt{
  220. width: 424rpx;
  221. height: 72rpx;
  222. line-height: 72rpx;
  223. text-align: center;
  224. position: fixed;
  225. bottom: 130rpx;
  226. left: 50%;
  227. transform: translateX(-50%);
  228. background:#3D90F4;
  229. border-radius: 42rpx;
  230. font-size: 32rpx;
  231. font-family: PingFang SC;
  232. font-weight: 400;
  233. color: #FFFFFF;
  234. z-index: 999;
  235. }
  236. .faceRecord-box{
  237. position: fixed;
  238. top: 0;
  239. bottom: 0;
  240. left: 0;
  241. right: 0;
  242. z-index: 9999;
  243. background-color: #fff;
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. flex-direction: column;
  248. .camera,.facePhoto{
  249. width: 450rpx;
  250. height: 450rpx;
  251. border-radius: 50%;
  252. border:2rpx solid #eaeaea;
  253. }
  254. .takePhotoBt{
  255. display: inline-block;
  256. margin: 40rpx 0;
  257. }
  258. .camera-submit{
  259. width: 424rpx;
  260. height: 72rpx;
  261. line-height: 72rpx;
  262. text-align: center;
  263. background:#3D90F4;
  264. border-radius: 42rpx;
  265. font-size: 32rpx;
  266. font-family: PingFang SC;
  267. font-weight: 400;
  268. color: #FFFFFF;
  269. margin: 40rpx auto;
  270. &.cancel{
  271. color: #fff;
  272. background-color: #ED834A;
  273. border-color: #ED834A;
  274. margin: 0 auto 50rpx;
  275. }
  276. }
  277. }
  278. }
  279. </style>