index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. uni.navigateTo({
  84. url,
  85. });
  86. let that = this;
  87. switch (index) {
  88. case 0: //我的建议
  89. break;
  90. case 1: //我的报名
  91. break;
  92. case 2: //我的收藏
  93. break;
  94. case 3: //退出登录
  95. if (that.isAuth) {
  96. uni.showModal({
  97. title: "确定退出登录吗?",
  98. success(res) {
  99. if (res.confirm) {
  100. that.loginOut();
  101. } else if (res.cancel) {
  102. console.log("用户点击取消");
  103. }
  104. },
  105. });
  106. } else {
  107. uni.showToast({
  108. title: "您还没有登录",
  109. duration: 2500,
  110. icon: "none",
  111. });
  112. }
  113. break;
  114. }
  115. },
  116. loginOut() {
  117. let md5Sign = md5(
  118. "method=" +
  119. "user" +
  120. "&timestamp=" +
  121. getApp().globalData.globalTimestamp +
  122. "&secret=" +
  123. getApp().globalData.secret
  124. );
  125. let url =
  126. getApp().globalData.shareUrl +
  127. "api/api.php" +
  128. "?method=user&action=logout&timestamp=" +
  129. getApp().globalData.globalTimestamp +
  130. "&sign=" +
  131. md5Sign;
  132. uni.request({
  133. url: url,
  134. method: "POST",
  135. header: {
  136. "content-type": "application/x-www-form-urlencoded",
  137. },
  138. data: {
  139. openId: getApp().globalData.open_id,
  140. },
  141. success: (res) => {
  142. if (res.data.code === 200) {
  143. this.isAuth = false;
  144. getApp().globalData.isAuth = false;
  145. getApp().globalData.user_headUrl = "";
  146. getApp().globalData.user_name = "";
  147. getApp().globalData.user_phone = "";
  148. uni.showToast({
  149. title: "退出登录成功",
  150. duration: 2500,
  151. icon: "none",
  152. });
  153. }
  154. },
  155. fail: () => {
  156. console.log("连接失败");
  157. },
  158. });
  159. },
  160. getUserInfo() {
  161. let md5Sign = md5(
  162. "method=" +
  163. "user" +
  164. "&timestamp=" +
  165. getApp().globalData.globalTimestamp +
  166. "&secret=" +
  167. getApp().globalData.secret
  168. );
  169. let url =
  170. getApp().globalData.shareUrl +
  171. "api/api.php" +
  172. "?method=user&action=info_by_openid&timestamp=" +
  173. getApp().globalData.globalTimestamp +
  174. "&sign=" +
  175. md5Sign;
  176. uni.request({
  177. url: url,
  178. method: "POST",
  179. header: {
  180. "content-type": "application/x-www-form-urlencoded",
  181. },
  182. data: {
  183. openId: getApp().globalData.open_id,
  184. },
  185. success: (res) => {
  186. if (res.data.code === 200) {
  187. if (res.data.data.nickname) {
  188. this.isAuth = true;
  189. this.userHeadImg = res.data.data.headimg;
  190. this.userNickName = res.data.data.nickname;
  191. getApp().globalData.user_phone = res.data.data.phone;
  192. } else {
  193. this.isAuth = false;
  194. }
  195. }
  196. },
  197. fail: () => {
  198. console.log("连接失败");
  199. },
  200. });
  201. },
  202. getSwiperList() {
  203. let md5Sign = md5(
  204. "method=" +
  205. "common" +
  206. "&timestamp=" +
  207. getApp().globalData.globalTimestamp +
  208. "&secret=" +
  209. getApp().globalData.secret
  210. );
  211. let url =
  212. getApp().globalData.shareUrl +
  213. "api/api.php" +
  214. "?method=common&source=main_pics&action=list&timestamp=" +
  215. getApp().globalData.globalTimestamp +
  216. "&sign=" +
  217. md5Sign;
  218. uni.request({
  219. url: url,
  220. method: "POST",
  221. header: {
  222. "content-type": "application/x-www-form-urlencoded",
  223. },
  224. data: {
  225. order_by: "weight desc",
  226. s_status: 1,
  227. },
  228. success: (res) => {
  229. if (res.data.code === 200) {
  230. this.swiperBackground =
  231. getApp().globalData.shareUrl + res.data.data.list[0].pic_path;
  232. }
  233. },
  234. fail: () => {
  235. console.log("连接失败");
  236. },
  237. });
  238. },
  239. },
  240. };
  241. </script>
  242. <style lang="scss" scoped>
  243. .content {
  244. display: flex;
  245. flex-direction: column;
  246. .self-inf {
  247. position: relative;
  248. height: 440rpx;
  249. width: 100%;
  250. display: flex;
  251. margin-bottom: 80rpx;
  252. border-radius: 0rpx 0rpx 100% 100%;
  253. .img-name-box {
  254. height: 150rpx;
  255. margin-top: 110rpx;
  256. display: flex;
  257. align-items: center;
  258. .auth-btn {
  259. margin-left: 30rpx;
  260. margin-top: 20rpx;
  261. font-size: 28rpx;
  262. background-color: #02a7f0;
  263. color: #fff;
  264. }
  265. .heade-img {
  266. z-index: 1;
  267. width: 100rpx;
  268. height: 100rpx;
  269. border-radius: 50%;
  270. margin-left: 80rpx;
  271. }
  272. }
  273. .bg-img {
  274. z-index: -1;
  275. position: absolute;
  276. width: 100%;
  277. height: 100%;
  278. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  279. }
  280. .groove-img {
  281. width: 100%;
  282. height: 100rpx;
  283. bottom: -22rpx;
  284. position: absolute;
  285. }
  286. .nickname {
  287. font-weight: 600;
  288. font-size: 28rpx;
  289. margin-left: 30rpx;
  290. margin-top: 20rpx;
  291. color: #ffffff;
  292. letter-spacing: 1rpx;
  293. }
  294. }
  295. .options {
  296. padding: 70rpx;
  297. z-index: 99;
  298. position: relative;
  299. top: -270rpx;
  300. .options-item {
  301. background-color: #fff;
  302. display: flex;
  303. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  304. border-radius: 32rpx;
  305. margin-top: 20px;
  306. height: 150rpx;
  307. align-items: center;
  308. .img-box {
  309. margin-left: 40rpx;
  310. .options-item-img {
  311. width: 56rpx;
  312. height: 56rpx;
  313. }
  314. }
  315. .options-item-name {
  316. margin-left: 40rpx;
  317. font-weight: 600;
  318. font-size: 30rpx;
  319. margin-bottom: 10rpx;
  320. }
  321. }
  322. }
  323. }
  324. .fontGrey {
  325. color: $uni-text-color-grey;
  326. }
  327. </style>