index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="content">
  3. <top-title :titleValue="title" style="width: 100%;"></top-title>
  4. <div class="self-inf">
  5. <div class="img-name-box" v-if="isAuth">
  6. <image :src="userHeadImg" class="heade-img" mode="aspectFill"></image>
  7. <p class="nickname">{{ userNickName }}</p>
  8. </div>
  9. <view class="img-name-box" v-if="!isAuth">
  10. <image src="/static/auth-icon.png" class="heade-img" mode="aspectFill"></image>
  11. <button @click="goAuthPage()" class="auth-btn">授权登录</button>
  12. </view>
  13. <image class="bg-img" :src="swiperBackground" mode="aspectFill"></image>
  14. <image src="../../static/Intersect.svg" class="groove-img"></image>
  15. </div>
  16. <div class="options">
  17. <div
  18. v-for="(item, idx) in list"
  19. :key="idx"
  20. class="options-item"
  21. @click="goDetailFn(idx, item.url)"
  22. >
  23. <div class="img-box">
  24. <img :src="item.icoin" alt="" class="options-item-img" /><span></span>
  25. </div>
  26. <div
  27. class="options-item-name"
  28. :class="{ fontGrey: idx == list.length - 1 }"
  29. >
  30. {{ item.name }}
  31. </div>
  32. </div>
  33. </div>
  34. <foot-tabs :selectedIndex='1'></foot-tabs>
  35. </view>
  36. </template>
  37. <script>
  38. import md5 from "@/common/md5.js";
  39. import topTitle from '@/components/top-title/top-title.vue';
  40. import footTabs from '@/components/foot-tabs/footTabs.vue';
  41. export default {
  42. components: {
  43. 'foot-tabs': footTabs,
  44. 'top-title': topTitle
  45. },
  46. data() {
  47. return {
  48. title: "个人中心",
  49. isAuth: true,
  50. userHeadImg: "",
  51. userNickName: "",
  52. list: [
  53. { icoin: "/static/selfCenter/suggest.png", name: "我的建议" },
  54. { icoin: "/static/selfCenter/sign.png", name: "我的报名" },
  55. {
  56. icoin: "/static/selfCenter/collection.png",
  57. name: "我的收藏",
  58. url: "/pages/selfCenter/collection",
  59. },
  60. { icoin: "/static/selfCenter/back.png", name: "退出登录" },
  61. ],
  62. swiperBackground: "",
  63. };
  64. },
  65. onLoad() {
  66. this.getSwiperList();
  67. },
  68. onShow() {
  69. // this.isAuth = getApp().globalData.isAuth;
  70. // if(this.isAuth){
  71. // this.userHeadImg = getApp().globalData.user_headUrl;
  72. // this.userNickName = getApp().globalData.user_name;
  73. // }
  74. this.getUserInfo();
  75. },
  76. methods: {
  77. goAuthPage() {
  78. uni.navigateTo({
  79. url: "../auth/index",
  80. });
  81. },
  82. goDetailFn(index, url) {
  83. let that = this;
  84. switch (index) {
  85. case 0: //我的建议
  86. break;
  87. case 1: //我的报名
  88. break;
  89. case 2: //我的收藏
  90. if(that.isAuth){
  91. uni.navigateTo({
  92. url,
  93. });
  94. }else {
  95. uni.showToast({
  96. title: "您还没有登录授权",
  97. duration: 2500,
  98. icon: "none",
  99. });
  100. }
  101. break;
  102. case 3: //退出登录
  103. if (that.isAuth) {
  104. uni.showModal({
  105. title: "确定退出登录吗?",
  106. success(res) {
  107. if (res.confirm) {
  108. that.loginOut();
  109. } else if (res.cancel) {
  110. console.log("用户点击取消");
  111. }
  112. },
  113. });
  114. } else {
  115. uni.showToast({
  116. title: "您还没有登录授权",
  117. duration: 2500,
  118. icon: "none",
  119. });
  120. }
  121. break;
  122. }
  123. },
  124. loginOut() {
  125. let md5Sign = md5(
  126. "method=" +
  127. "user" +
  128. "&timestamp=" +
  129. getApp().globalData.globalTimestamp +
  130. "&secret=" +
  131. getApp().globalData.secret
  132. );
  133. let url =
  134. getApp().globalData.shareUrl +
  135. "api/api.php" +
  136. "?method=user&action=logout&timestamp=" +
  137. getApp().globalData.globalTimestamp +
  138. "&sign=" +
  139. md5Sign;
  140. uni.request({
  141. url: url,
  142. method: "POST",
  143. header: {
  144. "content-type": "application/x-www-form-urlencoded",
  145. },
  146. data: {
  147. openId: getApp().globalData.open_id,
  148. },
  149. success: (res) => {
  150. if (res.data.code === 200) {
  151. this.isAuth = false;
  152. getApp().globalData.isAuth = false;
  153. getApp().globalData.user_headUrl = "";
  154. getApp().globalData.user_name = "";
  155. getApp().globalData.user_phone = "";
  156. uni.showToast({
  157. title: "退出登录成功",
  158. duration: 2500,
  159. icon: "none",
  160. });
  161. }
  162. },
  163. fail: () => {
  164. console.log("连接失败");
  165. },
  166. });
  167. },
  168. getUserInfo() {
  169. let md5Sign = md5(
  170. "method=" +
  171. "user" +
  172. "&timestamp=" +
  173. getApp().globalData.globalTimestamp +
  174. "&secret=" +
  175. getApp().globalData.secret
  176. );
  177. let url =
  178. getApp().globalData.shareUrl +
  179. "api/api.php" +
  180. "?method=user&action=info_by_openid&timestamp=" +
  181. getApp().globalData.globalTimestamp +
  182. "&sign=" +
  183. md5Sign;
  184. uni.request({
  185. url: url,
  186. method: "POST",
  187. header: {
  188. "content-type": "application/x-www-form-urlencoded",
  189. },
  190. data: {
  191. openId: getApp().globalData.open_id,
  192. },
  193. success: (res) => {
  194. if (res.data.code === 200) {
  195. if (res.data.data.nickname) {
  196. this.isAuth = true;
  197. this.userHeadImg = res.data.data.headimg;
  198. this.userNickName = res.data.data.nickname;
  199. getApp().globalData.user_phone = res.data.data.phone;
  200. } else {
  201. this.isAuth = false;
  202. }
  203. }
  204. },
  205. fail: () => {
  206. console.log("连接失败");
  207. },
  208. });
  209. },
  210. getSwiperList() {
  211. let md5Sign = md5(
  212. "method=" +
  213. "common" +
  214. "&timestamp=" +
  215. getApp().globalData.globalTimestamp +
  216. "&secret=" +
  217. getApp().globalData.secret
  218. );
  219. let url =
  220. getApp().globalData.shareUrl +
  221. "api/api.php" +
  222. "?method=common&source=main_pics&action=list&timestamp=" +
  223. getApp().globalData.globalTimestamp +
  224. "&sign=" +
  225. md5Sign;
  226. uni.request({
  227. url: url,
  228. method: "POST",
  229. header: {
  230. "content-type": "application/x-www-form-urlencoded",
  231. },
  232. data: {
  233. order_by: "weight desc",
  234. s_status: 1,
  235. },
  236. success: (res) => {
  237. if (res.data.code === 200) {
  238. this.swiperBackground =
  239. getApp().globalData.shareUrl + res.data.data.list[0].pic_path;
  240. }
  241. },
  242. fail: () => {
  243. console.log("连接失败");
  244. },
  245. });
  246. },
  247. },
  248. };
  249. </script>
  250. <style lang="scss" scoped>
  251. .content {
  252. display: flex;
  253. flex-direction: column;
  254. .self-inf {
  255. position: relative;
  256. height: 440rpx;
  257. width: 100%;
  258. display: flex;
  259. margin-bottom: 80rpx;
  260. border-radius: 0rpx 0rpx 100% 100%;
  261. .img-name-box {
  262. height: 150rpx;
  263. margin-top: 110rpx;
  264. display: flex;
  265. align-items: center;
  266. .auth-btn {
  267. margin-left: 30rpx;
  268. margin-top: 20rpx;
  269. font-size: 28rpx;
  270. background-color: #02a7f0;
  271. color: #fff;
  272. }
  273. .heade-img {
  274. z-index: 1;
  275. width: 100rpx;
  276. height: 100rpx;
  277. border-radius: 50%;
  278. margin-left: 80rpx;
  279. }
  280. }
  281. .bg-img {
  282. z-index: -1;
  283. position: absolute;
  284. width: 100%;
  285. height: 100%;
  286. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  287. }
  288. .groove-img {
  289. width: 100%;
  290. height: 100rpx;
  291. bottom: -22rpx;
  292. position: absolute;
  293. }
  294. .nickname {
  295. font-weight: 600;
  296. font-size: 28rpx;
  297. margin-left: 30rpx;
  298. margin-top: 20rpx;
  299. color: #ffffff;
  300. letter-spacing: 1rpx;
  301. }
  302. }
  303. .options {
  304. padding: 70rpx;
  305. z-index: 99;
  306. position: relative;
  307. top: -270rpx;
  308. .options-item {
  309. background-color: #fff;
  310. display: flex;
  311. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  312. border-radius: 32rpx;
  313. margin-top: 20px;
  314. height: 150rpx;
  315. align-items: center;
  316. .img-box {
  317. margin-left: 40rpx;
  318. .options-item-img {
  319. width: 56rpx;
  320. height: 56rpx;
  321. }
  322. }
  323. .options-item-name {
  324. margin-left: 40rpx;
  325. font-weight: 600;
  326. font-size: 30rpx;
  327. margin-bottom: 10rpx;
  328. }
  329. }
  330. }
  331. }
  332. .fontGrey {
  333. color: $uni-text-color-grey;
  334. }
  335. </style>