index.vue 8.9 KB

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