index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view class="content">
  3. <view class="self-inf">
  4. <view class="antu-box" v-if="isAuth">
  5. <view class="img-name-box">
  6. <image :src="userHeadImg" class="heade-img" mode="aspectFill"></image>
  7. <p class="nickname">{{ userNickName }}</p>
  8. <p class="nickname">136****0648</p>
  9. </view>
  10. <view class="org-info-box">
  11. <view class="org-info">浐灞一支部</view>
  12. <view class="org-line"></view>
  13. <view class="org-info">宣传委员</view>
  14. </view>
  15. </view>
  16. <view class="img-name-box" v-if="!isAuth" style="height: 180rpx;">
  17. <image src="/static/auth-icon.png" class="heade-img" mode="aspectFill" style="margin-left: 80rpx;"></image>
  18. <button @click="goAuthPage()" class="auth-btn">授权登录</button>
  19. </view>
  20. <!-- <image class="bg-img" :src="swiperBackground" mode="aspectFill"></image> -->
  21. </view>
  22. <view class="options">
  23. <view v-for="(item, idx) in list" :key="idx" class="options-item" @click="goDetailFn(idx, item.url)" v-if="item.isShow">
  24. <view class="img-box">
  25. <img :src="item.icon" alt="" class="options-item-img" />
  26. </view>
  27. <view class="options-item-name">
  28. {{ item.name }}
  29. </view>
  30. </view>
  31. </view>
  32. <!-- <button class="submit-btn" @click="goUpload()">上传</button> -->
  33. </view>
  34. </template>
  35. <script>
  36. import md5 from "@/common/md5.js";
  37. export default {
  38. components: {
  39. },
  40. data() {
  41. return {
  42. isAuth: true,
  43. userHeadImg: "",
  44. userNickName: "",
  45. userscanCode:"",
  46. list: [
  47. {
  48. icon: "/static/upload.png",
  49. name: "内容上传" ,
  50. url: "/pages/index/upload/upload",
  51. isShow:false,
  52. },
  53. {
  54. icon: "/static/sign.png",
  55. name: "发布记录" ,
  56. url: "/pages/index/record/record",
  57. isShow:false,
  58. },
  59. {
  60. icon: "/static/scan.png",
  61. name: "扫码" ,
  62. // url: "/pages/index/scanCode/index",
  63. isShow:true,
  64. },
  65. {
  66. icon: "/static/self-icon.png",
  67. name: "个人信息" ,
  68. url: "/pages/index/self_info",
  69. isShow:true,
  70. },
  71. {
  72. icon: "/static/org-icon.png",
  73. name: "组织成员" ,
  74. url: "/pages/index/org_member",
  75. isShow:true,
  76. },
  77. {
  78. icon: "/static/explain-icon.png",
  79. name: "后台登录" ,
  80. url: "/pages/index/back_login",
  81. isShow:true,
  82. },
  83. {
  84. icon: "/static/back.png",
  85. name: "退出登录" ,
  86. // url: "/pages/index/scanCode/index",
  87. isShow:true,
  88. },
  89. ],
  90. };
  91. },
  92. async onLoad() {
  93. // setTimeout(()=>{
  94. // this.getUserInfo()
  95. // },1000)
  96. await this.$getOpenId
  97. this.getUserInfo()
  98. },
  99. onShow() {
  100. },
  101. methods: {
  102. goAuthPage() {
  103. uni.navigateTo({
  104. url: "./auth/index",
  105. });
  106. },
  107. goUpload(){
  108. let that = this;
  109. if(!that.isAuth){
  110. uni.showToast({
  111. title: "您还没有授权",
  112. duration: 2500,
  113. icon: "none",
  114. });
  115. return;
  116. }else {
  117. uni.navigateTo({
  118. url: "/pages/index/upload/upload",
  119. })
  120. }
  121. },
  122. getUserInfo() {
  123. let md5Sign = md5(
  124. "method=" +
  125. "user" +
  126. "&timestamp=" +
  127. getApp().globalData.globalTimestamp +
  128. "&secret=" +
  129. getApp().globalData.secret
  130. );
  131. let url =
  132. getApp().globalData.shareUrl +
  133. "api/api.php" +
  134. "?method=user&action=info_by_openid&timestamp=" +
  135. getApp().globalData.globalTimestamp +
  136. "&sign=" +
  137. md5Sign;
  138. uni.request({
  139. url: url,
  140. method: "POST",
  141. header: {
  142. "content-type": "application/x-www-form-urlencoded",
  143. },
  144. data: {
  145. openid:getApp().globalData.open_id,
  146. },
  147. success: (res) => {
  148. if (res.data.code === 200) {
  149. if (res.data.data.nickname) {
  150. this.isAuth = true;
  151. this.userHeadImg = res.data.data.headimg;
  152. this.userNickName = res.data.data.nickname;
  153. getApp().globalData.globalAuth = true;
  154. getApp().globalData.user_name = res.data.data.nickname;
  155. getApp().globalData.user_headUrl = res.data.data.headimg;
  156. getApp().globalData.user_department = res.data.data.department;
  157. getApp().globalData.user_real_name = res.data.data.real_name;
  158. }else {
  159. this.isAuth = false;
  160. getApp().globalData.globalAuth = false;
  161. }
  162. }
  163. },
  164. fail: () => {
  165. console.log("连接失败");
  166. },
  167. });
  168. },
  169. uploadUserInfo(name,head){
  170. },
  171. getAuth() {
  172. // uni.getUserProfile({
  173. // desc:'登录',
  174. // success:(res)=> {
  175. // this.userHeadImg = res.userInfo.avatarUrl;
  176. // this.userNickName = res.userInfo.nickName;
  177. // this.uploadUserInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
  178. // this.isAuth = true;
  179. // getApp().globalData.isAuth = true;
  180. // },
  181. // fail:(err)=> {
  182. // console.log(err)
  183. // getApp().globalData.isAuth = false;
  184. // getApp().globalData.globalAuth = false;
  185. // this.isAuth = false;
  186. // }
  187. // })
  188. },
  189. getUserPhone(){
  190. },
  191. codeReg(strs){
  192. let reg = /\[(.*?)\]/gi;
  193. let str = strs;
  194. let tmp = str.match(reg) , result = '';
  195. if (tmp) {
  196. for (let i = 0; i < tmp.length; i++) {
  197. result = tmp[i].replace(reg, "$1")
  198. }
  199. } else {
  200. console.log("no match.");
  201. }
  202. console.log(result)
  203. this.getScanCode(result)
  204. },
  205. getScanCode(codeRes) {
  206. let md5Sign = md5(
  207. "method=" +
  208. "user" +
  209. "&timestamp=" +
  210. getApp().globalData.globalTimestamp +
  211. "&secret=" +
  212. getApp().globalData.secret
  213. );
  214. let url =
  215. getApp().globalData.shareUrl +
  216. "api/api.php" +
  217. "?method=user&action=qrcode_login&timestamp=" +
  218. getApp().globalData.globalTimestamp +
  219. "&sign=" +
  220. md5Sign;
  221. uni.request({
  222. url: url,
  223. method: "POST",
  224. header: {
  225. "content-type": "application/x-www-form-urlencoded",
  226. },
  227. data: {
  228. openid:getApp().globalData.open_id,
  229. qrcode:codeRes
  230. },
  231. success: (res) => {
  232. if (res.data.code === 200) {
  233. uni.showToast({
  234. title:res.data.msg,
  235. icon:'none'
  236. })
  237. } else {
  238. uni.showToast({
  239. title:res.data.msg,
  240. icon:'none'
  241. })
  242. }
  243. },
  244. fail: () => {
  245. console.log("连接失败");
  246. },
  247. });
  248. },
  249. goDetailFn(index, url) {
  250. let that = this;
  251. if(!that.isAuth){
  252. uni.showToast({
  253. title: "您还没有授权",
  254. duration: 2500,
  255. icon: "none",
  256. });
  257. return;
  258. }
  259. switch (index) {
  260. case 0: //扫码
  261. uni.scanCode({
  262. success: function (res) {
  263. console.log('条码类型:' + res.scanType);
  264. console.log('条码内容:' + res.result);
  265. that.codeReg(res.result)
  266. }
  267. });
  268. break;
  269. case 1: //个人信息
  270. uni.navigateTo({
  271. url,
  272. });
  273. break;
  274. case 2: //组织成员
  275. uni.navigateTo({
  276. url,
  277. });
  278. break;
  279. case 3: //后台登录
  280. uni.navigateTo({
  281. url,
  282. });
  283. break;
  284. case 4: //退出登录
  285. uni.navigateTo({
  286. url,
  287. });
  288. break;
  289. default:
  290. uni.navigateTo({
  291. url,
  292. });
  293. }
  294. },
  295. },
  296. };
  297. </script>
  298. <style lang="scss" scoped>
  299. .content {
  300. display: flex;
  301. flex-direction: column;
  302. .self-inf {
  303. position: relative;
  304. height: 240rpx;
  305. width: 100%;
  306. // display: flex;
  307. // margin-bottom: 80rpx;
  308. background-color: #c2e3e6;
  309. // border-radius: 0rpx 0rpx 100% 100%;
  310. .img-name-box {
  311. height: 150rpx;
  312. margin-top: 20rpx;
  313. margin-bottom: 20rpx;
  314. display: flex;
  315. align-items: center;
  316. width: 85%;
  317. .auth-btn {
  318. margin-left: 30rpx;
  319. margin-top: 20rpx;
  320. font-size: 28rpx;
  321. background-color: #02a7f0;
  322. color: #fff;
  323. }
  324. .heade-img {
  325. z-index: 1;
  326. width: 100rpx;
  327. height: 100rpx;
  328. border-radius: 50%;
  329. // margin-left: 80rpx;
  330. }
  331. }
  332. .bg-img {
  333. z-index: -1;
  334. position: absolute;
  335. width: 100%;
  336. height: 100%;
  337. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  338. }
  339. .nickname {
  340. font-weight: 600;
  341. font-size: 28rpx;
  342. margin-left: 30rpx;
  343. margin-top: 20rpx;
  344. color: #555;
  345. letter-spacing: 1rpx;
  346. }
  347. }
  348. .options {
  349. padding: 80rpx 70rpx 20rpx 70rpx;
  350. z-index: 99;
  351. position: relative;
  352. .options-item {
  353. background-color: #fff;
  354. display: flex;
  355. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  356. border-radius: 32rpx;
  357. margin-top: 30rpx;
  358. height: 75px;
  359. align-items: center;
  360. .img-box {
  361. margin-left: 40rpx;
  362. .options-item-img {
  363. width: 56rpx;
  364. height: 56rpx;
  365. }
  366. }
  367. .options-item-name {
  368. margin-left: 40rpx;
  369. font-weight: 600;
  370. font-size: 30rpx;
  371. margin-bottom: 10rpx;
  372. }
  373. }
  374. }
  375. }
  376. .fontGrey {
  377. color: $uni-text-color-grey;
  378. }
  379. .antu-box {
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. background: #fff;
  384. border-radius: 10rpx;
  385. position: relative;
  386. z-index: 999;
  387. top: 25px;
  388. width: 80%;
  389. left: 10%;
  390. color: #555;
  391. box-shadow: 0px 2px 16px rgba(0, 0, 0, 0.2);
  392. }
  393. .submit-btn {
  394. color: white;
  395. font-weight: normal;
  396. width: 70%;
  397. border-radius: 20rpx;
  398. background-color: #02a7f0;
  399. margin: 50rpx auto;
  400. }
  401. .org-info-box {
  402. display: flex;
  403. justify-content: space-evenly;
  404. height: 80rpx;
  405. align-items: center;
  406. width: 100%;
  407. border-top: 1px solid #d4d4d4;
  408. color: #555;
  409. font-size: 28rpx;
  410. background: #fff;
  411. }
  412. .org-line {
  413. width: 1px;
  414. height: 82rpx;
  415. background: #d4d4d4;
  416. }
  417. </style>