index.vue 6.3 KB

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