index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="content">
  3. <div class="self-inf">
  4. <div class="img-name-box" v-if="isAuth">
  5. <image :src="userHeadImg" class="heade-img" mode="aspectFill"></image>
  6. <p class="nickname">{{ userNickName }}</p>
  7. </div>
  8. <view class="img-name-box" v-if="!isAuth">
  9. <image src="/static/auth-icon.png" class="heade-img" mode="aspectFill"></image>
  10. <button @click="getAuth()" class="auth-btn">授权登录</button>
  11. </view>
  12. <image class="bg-img" :src="swiperBackground" mode="aspectFill"></image>
  13. </div>
  14. <div class="options">
  15. <div v-for="(item, idx) in list" :key="idx" class="options-item" @click="goDetailFn(idx, item.url)" v-if="item.isShow">
  16. <div class="img-box">
  17. <img :src="item.icoin" alt="" class="options-item-img" />
  18. </div>
  19. <div class="options-item-name">
  20. {{ item.name }}
  21. </div>
  22. </div>
  23. </div>
  24. </view>
  25. </template>
  26. <script>
  27. import md5 from "@/common/md5.js";
  28. export default {
  29. components: {
  30. },
  31. data() {
  32. return {
  33. isAuth: false,
  34. userHeadImg: "/static/logo.png",
  35. userNickName: "子众",
  36. list: [
  37. {
  38. icoin: "/static/sign.png",
  39. name: "内容上传" ,
  40. url: "/pages/index/upload/upload",
  41. isShow:true,
  42. },
  43. {
  44. icoin: "/static/sign.png",
  45. name: "发布记录" ,
  46. url: "/pages/index/record/record",
  47. isShow:true,
  48. },
  49. ],
  50. };
  51. },
  52. onLoad() {
  53. },
  54. onShow() {
  55. // this.isAuth = getApp().globalData.isAuth;
  56. // if(this.isAuth){
  57. // this.userHeadImg = getApp().globalData.user_headUrl;
  58. // this.userNickName = getApp().globalData.user_name;
  59. // }
  60. // this.getUserInfo();
  61. },
  62. methods: {
  63. getAuth() {
  64. uni.getUserProfile({
  65. desc:'登录',
  66. success:(res)=> {
  67. // getApp().globalData.user_headUrl = res.userInfo.avatarUrl;
  68. // getApp().globalData.user_name = res.userInfo.nickName;
  69. this.userHeadImg = res.userInfo.avatarUrl;
  70. this.userNickName = res.userInfo.nickName;
  71. this.isAuth = true;
  72. getApp().globalData.isAuth = true;
  73. },
  74. fail:(err)=> {
  75. console.log(err)
  76. getApp().globalData.isAuth = false;
  77. getApp().globalData.globalAuth = false;
  78. this.isAuth = false;
  79. }
  80. })
  81. },
  82. goDetailFn(index, url) {
  83. let that = this;
  84. if(!that.isAuth){
  85. uni.showToast({
  86. title: "您还没有授权",
  87. duration: 2500,
  88. icon: "none",
  89. });
  90. return;
  91. }
  92. switch (index) {
  93. case 0: //内容上传
  94. uni.navigateTo({
  95. url,
  96. });
  97. break;
  98. case 1: //发布记录
  99. uni.navigateTo({
  100. url,
  101. });
  102. break;
  103. }
  104. },
  105. getUserInfo() {
  106. let md5Sign = md5(
  107. "method=" +
  108. "user" +
  109. "&timestamp=" +
  110. getApp().globalData.globalTimestamp +
  111. "&secret=" +
  112. getApp().globalData.secret
  113. );
  114. let url =
  115. getApp().globalData.shareUrl +
  116. "api/api.php" +
  117. "?method=user&action=info_by_openid&timestamp=" +
  118. getApp().globalData.globalTimestamp +
  119. "&sign=" +
  120. md5Sign;
  121. uni.request({
  122. url: url,
  123. method: "POST",
  124. header: {
  125. "content-type": "application/x-www-form-urlencoded",
  126. },
  127. data: {
  128. openId: getApp().globalData.open_id,
  129. },
  130. success: (res) => {
  131. if (res.data.code === 200) {
  132. }
  133. },
  134. fail: () => {
  135. console.log("连接失败");
  136. },
  137. });
  138. },
  139. },
  140. };
  141. </script>
  142. <style lang="scss" scoped>
  143. .content {
  144. display: flex;
  145. flex-direction: column;
  146. .self-inf {
  147. position: relative;
  148. height: 360rpx;
  149. width: 100%;
  150. display: flex;
  151. margin-bottom: 80rpx;
  152. background-color: #c2e3e6;
  153. // border-radius: 0rpx 0rpx 100% 100%;
  154. .img-name-box {
  155. height: 150rpx;
  156. margin-top:80rpx;
  157. display: flex;
  158. align-items: center;
  159. z-index: 99999;
  160. .auth-btn {
  161. margin-left: 30rpx;
  162. margin-top: 20rpx;
  163. font-size: 28rpx;
  164. background-color: #02a7f0;
  165. color: #fff;
  166. }
  167. .heade-img {
  168. z-index: 1;
  169. width: 100rpx;
  170. height: 100rpx;
  171. border-radius: 50%;
  172. margin-left: 80rpx;
  173. }
  174. }
  175. .bg-img {
  176. z-index: -1;
  177. position: absolute;
  178. width: 100%;
  179. height: 100%;
  180. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  181. }
  182. .nickname {
  183. font-weight: 600;
  184. font-size: 28rpx;
  185. margin-left: 30rpx;
  186. margin-top: 20rpx;
  187. color: #ffffff;
  188. letter-spacing: 1rpx;
  189. }
  190. }
  191. .options {
  192. padding: 70rpx;
  193. z-index: 99;
  194. position: relative;
  195. top: -270rpx;
  196. .options-item {
  197. background-color: #fff;
  198. display: flex;
  199. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  200. border-radius: 32rpx;
  201. margin-top: 20px;
  202. height: 150rpx;
  203. align-items: center;
  204. .img-box {
  205. margin-left: 40rpx;
  206. .options-item-img {
  207. width: 56rpx;
  208. height: 56rpx;
  209. }
  210. }
  211. .options-item-name {
  212. margin-left: 40rpx;
  213. font-weight: 600;
  214. font-size: 30rpx;
  215. margin-bottom: 10rpx;
  216. }
  217. }
  218. }
  219. }
  220. .fontGrey {
  221. color: $uni-text-color-grey;
  222. }
  223. </style>