index.vue 4.9 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: getApp().globalData.globalAuth,
  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. // if(this.isAuth){
  56. // this.userHeadImg = getApp().globalData.user_headUrl;
  57. // this.userNickName = getApp().globalData.user_name;
  58. // }
  59. },
  60. methods: {
  61. uploadUserInfo(name,head){
  62. let md5Sign = md5(
  63. "method=" +
  64. "user" +
  65. "&timestamp=" +
  66. getApp().globalData.globalTimestamp +
  67. "&secret=" +
  68. getApp().globalData.secret
  69. );
  70. let url =
  71. getApp().globalData.shareUrl +
  72. "api/api.php" +
  73. "?method=user&action=update&timestamp=" +
  74. getApp().globalData.globalTimestamp +
  75. "&sign=" +
  76. md5Sign;
  77. uni.request({
  78. url: url,
  79. method: "POST",
  80. header: {
  81. "content-type": "application/x-www-form-urlencoded",
  82. },
  83. data: {
  84. nickname:name,
  85. headimg:head,
  86. openid:getApp().globalData.open_id
  87. },
  88. success: (res) => {
  89. if (res.data.code === 200) {
  90. }
  91. },
  92. fail: () => {
  93. console.log("连接失败");
  94. },
  95. });
  96. },
  97. getAuth() {
  98. uni.getUserProfile({
  99. desc:'登录',
  100. success:(res)=> {
  101. this.userHeadImg = res.userInfo.avatarUrl;
  102. this.userNickName = res.userInfo.nickName;
  103. this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
  104. this.isAuth = true;
  105. getApp().globalData.isAuth = true;
  106. },
  107. fail:(err)=> {
  108. console.log(err)
  109. getApp().globalData.isAuth = false;
  110. getApp().globalData.globalAuth = false;
  111. this.isAuth = false;
  112. }
  113. })
  114. },
  115. goDetailFn(index, url) {
  116. let that = this;
  117. if(!that.isAuth){
  118. uni.showToast({
  119. title: "您还没有授权",
  120. duration: 2500,
  121. icon: "none",
  122. });
  123. return;
  124. }
  125. switch (index) {
  126. case 0: //内容上传
  127. uni.navigateTo({
  128. url,
  129. });
  130. break;
  131. case 1: //发布记录
  132. uni.navigateTo({
  133. url,
  134. });
  135. break;
  136. }
  137. },
  138. },
  139. };
  140. </script>
  141. <style lang="scss" scoped>
  142. .content {
  143. display: flex;
  144. flex-direction: column;
  145. .self-inf {
  146. position: relative;
  147. height: 360rpx;
  148. width: 100%;
  149. display: flex;
  150. margin-bottom: 80rpx;
  151. background-color: #c2e3e6;
  152. // border-radius: 0rpx 0rpx 100% 100%;
  153. .img-name-box {
  154. height: 150rpx;
  155. margin-top:80rpx;
  156. display: flex;
  157. align-items: center;
  158. z-index: 99999;
  159. .auth-btn {
  160. margin-left: 30rpx;
  161. margin-top: 20rpx;
  162. font-size: 28rpx;
  163. background-color: #02a7f0;
  164. color: #fff;
  165. }
  166. .heade-img {
  167. z-index: 1;
  168. width: 100rpx;
  169. height: 100rpx;
  170. border-radius: 50%;
  171. margin-left: 80rpx;
  172. }
  173. }
  174. .bg-img {
  175. z-index: -1;
  176. position: absolute;
  177. width: 100%;
  178. height: 100%;
  179. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  180. }
  181. .nickname {
  182. font-weight: 600;
  183. font-size: 28rpx;
  184. margin-left: 30rpx;
  185. margin-top: 20rpx;
  186. color: #ffffff;
  187. letter-spacing: 1rpx;
  188. }
  189. }
  190. .options {
  191. padding: 70rpx;
  192. z-index: 99;
  193. position: relative;
  194. top: -270rpx;
  195. .options-item {
  196. background-color: #fff;
  197. display: flex;
  198. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  199. border-radius: 32rpx;
  200. margin-top: 20px;
  201. height: 150rpx;
  202. align-items: center;
  203. .img-box {
  204. margin-left: 40rpx;
  205. .options-item-img {
  206. width: 56rpx;
  207. height: 56rpx;
  208. }
  209. }
  210. .options-item-name {
  211. margin-left: 40rpx;
  212. font-weight: 600;
  213. font-size: 30rpx;
  214. margin-bottom: 10rpx;
  215. }
  216. }
  217. }
  218. }
  219. .fontGrey {
  220. color: $uni-text-color-grey;
  221. }
  222. </style>