index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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: true,
  34. userHeadImg: "",
  35. userNickName: "",
  36. list: [
  37. {
  38. icoin: "/static/upload.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. async onLoad() {
  53. // setTimeout(()=>{
  54. // this.getUserInfo()
  55. // },1000)
  56. await this.$getOpenId
  57. this.getUserInfo()
  58. },
  59. onShow() {
  60. },
  61. methods: {
  62. getUserInfo() {
  63. let md5Sign = md5(
  64. "method=" +
  65. "user" +
  66. "&timestamp=" +
  67. getApp().globalData.globalTimestamp +
  68. "&secret=" +
  69. getApp().globalData.secret
  70. );
  71. let url =
  72. getApp().globalData.shareUrl +
  73. "api/api.php" +
  74. "?method=user&action=info_by_openid&timestamp=" +
  75. getApp().globalData.globalTimestamp +
  76. "&sign=" +
  77. md5Sign;
  78. uni.request({
  79. url: url,
  80. method: "POST",
  81. header: {
  82. "content-type": "application/x-www-form-urlencoded",
  83. },
  84. data: {
  85. openid:getApp().globalData.open_id,
  86. },
  87. success: (res) => {
  88. if (res.data.code === 200) {
  89. if (res.data.data.nickname) {
  90. this.isAuth = true;
  91. this.userHeadImg = res.data.data.headimg;
  92. this.userNickName = res.data.data.nickname;
  93. getApp().globalData.user_department = res.data.data.department;
  94. getApp().globalData.user_real_name = res.data.data.real_name;
  95. } else {
  96. this.isAuth = false;
  97. }
  98. }
  99. },
  100. fail: () => {
  101. console.log("连接失败");
  102. },
  103. });
  104. },
  105. uploadUserInfo(name,head){
  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=update&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. nickname:name,
  129. headimg:head,
  130. openid:getApp().globalData.open_id
  131. },
  132. success: (res) => {
  133. if (res.data.code === 200) {
  134. }
  135. },
  136. fail: () => {
  137. console.log("连接失败");
  138. },
  139. });
  140. },
  141. getAuth() {
  142. uni.getUserProfile({
  143. desc:'登录',
  144. success:(res)=> {
  145. this.userHeadImg = res.userInfo.avatarUrl;
  146. this.userNickName = res.userInfo.nickName;
  147. this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
  148. this.isAuth = true;
  149. getApp().globalData.isAuth = true;
  150. },
  151. fail:(err)=> {
  152. console.log(err)
  153. getApp().globalData.isAuth = false;
  154. getApp().globalData.globalAuth = false;
  155. this.isAuth = false;
  156. }
  157. })
  158. },
  159. goDetailFn(index, url) {
  160. let that = this;
  161. if(!that.isAuth){
  162. uni.showToast({
  163. title: "您还没有授权",
  164. duration: 2500,
  165. icon: "none",
  166. });
  167. return;
  168. }
  169. switch (index) {
  170. case 0: //内容上传
  171. uni.navigateTo({
  172. url,
  173. });
  174. break;
  175. case 1: //发布记录
  176. uni.navigateTo({
  177. url,
  178. });
  179. break;
  180. }
  181. },
  182. },
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .content {
  187. display: flex;
  188. flex-direction: column;
  189. .self-inf {
  190. position: relative;
  191. height: 360rpx;
  192. width: 100%;
  193. display: flex;
  194. margin-bottom: 80rpx;
  195. background-color: #c2e3e6;
  196. // border-radius: 0rpx 0rpx 100% 100%;
  197. .img-name-box {
  198. height: 150rpx;
  199. margin-top:80rpx;
  200. display: flex;
  201. align-items: center;
  202. z-index: 99999;
  203. .auth-btn {
  204. margin-left: 30rpx;
  205. margin-top: 20rpx;
  206. font-size: 28rpx;
  207. background-color: #02a7f0;
  208. color: #fff;
  209. }
  210. .heade-img {
  211. z-index: 1;
  212. width: 100rpx;
  213. height: 100rpx;
  214. border-radius: 50%;
  215. margin-left: 80rpx;
  216. }
  217. }
  218. .bg-img {
  219. z-index: -1;
  220. position: absolute;
  221. width: 100%;
  222. height: 100%;
  223. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  224. }
  225. .nickname {
  226. font-weight: 600;
  227. font-size: 28rpx;
  228. margin-left: 30rpx;
  229. margin-top: 20rpx;
  230. color: #ffffff;
  231. letter-spacing: 1rpx;
  232. }
  233. }
  234. .options {
  235. padding: 70rpx;
  236. z-index: 99;
  237. position: relative;
  238. top: -270rpx;
  239. .options-item {
  240. background-color: #fff;
  241. display: flex;
  242. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  243. border-radius: 32rpx;
  244. margin-top: 20px;
  245. height: 150rpx;
  246. align-items: center;
  247. .img-box {
  248. margin-left: 40rpx;
  249. .options-item-img {
  250. width: 56rpx;
  251. height: 56rpx;
  252. }
  253. }
  254. .options-item-name {
  255. margin-left: 40rpx;
  256. font-weight: 600;
  257. font-size: 30rpx;
  258. margin-bottom: 10rpx;
  259. }
  260. }
  261. }
  262. }
  263. .fontGrey {
  264. color: $uni-text-color-grey;
  265. }
  266. </style>