index.vue 6.4 KB

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