index.vue 8.4 KB

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