index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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">{{userPhone}}</p>
  9. </view>
  10. <view class="org-info-box" v-for="(item,index) in userPosList" :key="index">
  11. <view class="org-info">{{item.name || '-'}}</view>
  12. <!-- <view class="org-line"></view> -->
  13. <view class="org-info">{{item.position}}</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" :style="{paddingTop:(posLength > 1 ? '160rpx':'80rpx')} ">
  23. <!-- <view class="options" :class="{ paddingTop80: userPosList.length > 1 }"> -->
  24. <view v-for="(item, idx) in list" :key="idx" class="options-item" @click="goDetailFn(idx, item.url)" v-if="item.isShow">
  25. <view class="img-box">
  26. <img :src="item.icon" alt="" class="options-item-img" />
  27. </view>
  28. <view class="options-item-name">
  29. {{ item.name }}
  30. </view>
  31. </view>
  32. </view>
  33. <uni-popup ref="popup" type="center" :is-mask-click="false">
  34. <view class="auth-pop">
  35. <image src="/static/logo.png" mode="aspectFill"></image>
  36. <text class="margin-top-3 auth-title">欢迎使用农工笔记小程序</text>
  37. <text class="margin-top-3 auth-content">此页面是微信授权页面,授权之后你可以获取更优质的服务,您的隐私将会受到保护</text>
  38. <view class="margin-top-3">
  39. <!-- <button type='default' class="refuse" @click="goAuthPage">去授权</button>-->
  40. <button type='primary' class="allow" @click="getUserInfo()" v-if="!isAuth">登录授权</button>
  41. <button type="primary" class="allow" open-type="getPhoneNumber" style="font-size: 12px;"
  42. @getphonenumber="getPhoneNumber" v-if="isAuth && !isNeedPhone">手机号码授权</button>
  43. </view>
  44. </view>
  45. </uni-popup>
  46. <!-- <button class="submit-btn" @click="goUpload()">上传</button> -->
  47. </view>
  48. </template>
  49. <script>
  50. import md5 from "@/common/md5.js";
  51. export default {
  52. components: {
  53. },
  54. data() {
  55. return {
  56. isAuth: true,
  57. userHeadImg: "",
  58. userNickName: "",
  59. userPhone:'',
  60. userBranch:'',
  61. userPosList:[],
  62. posLength:0,
  63. userPos:'',
  64. userscanCode:"",
  65. iv:'',
  66. encryptedData:'',
  67. isNeedPhone:getApp().globalData.user_phone,
  68. list: [
  69. // {
  70. // icon: "/static/upload.png",
  71. // name: "内容上传" ,
  72. // url: "/pages/index/upload/upload",
  73. // isShow:false,
  74. // },
  75. // {
  76. // icon: "/static/sign.png",
  77. // name: "发布记录" ,
  78. // url: "/pages/index/record/record",
  79. // isShow:false,
  80. // },
  81. {
  82. icon: "/static/scan.png",
  83. name: "扫码" ,
  84. // url: "/pages/index/scanCode/index",
  85. isShow:true,
  86. },
  87. {
  88. icon: "/static/self-icon.png",
  89. name: "个人信息" ,
  90. url: "/pages/index/self_info",
  91. isShow:true,
  92. },
  93. {
  94. icon: "/static/org-icon.png",
  95. name: "组织成员" ,
  96. url: "/pages/index/org_member",
  97. isShow:true,
  98. },
  99. {
  100. icon: "/static/explain-icon.png",
  101. name: "后台登录" ,
  102. url: "/pages/index/back_login",
  103. isShow:true,
  104. },
  105. {
  106. icon: "/static/back.png",
  107. name: "退出登录" ,
  108. // url: "/pages/index/scanCode/index",
  109. isShow:true,
  110. },
  111. ],
  112. };
  113. },
  114. async onLoad() {
  115. // setTimeout(()=>{
  116. // this.getUserInfo()
  117. // },1000)
  118. await this.$getOpenId
  119. this.getUserInfoData()
  120. },
  121. onShow() {
  122. },
  123. methods: {
  124. goAuthPage() {
  125. uni.navigateTo({
  126. url: "./auth/index",
  127. });
  128. },
  129. open(){
  130. // 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ,type 属性将失效 ,仅支持 ['top','left','bottom','right','center']
  131. uni.hideTabBar()
  132. this.$refs.popup.open('center')
  133. },
  134. getUserInfo() {
  135. uni.getUserProfile({
  136. desc:'登录',
  137. success:(res)=> {
  138. getApp().globalData.user_headUrl = res.userInfo.avatarUrl;
  139. getApp().globalData.user_name = res.userInfo.nickName;
  140. this.userHeadImg = res.userInfo.avatarUrl;
  141. this.userNickName = res.userInfo.nickName;
  142. this.iv = res.iv;
  143. this.encryptedData = res.encryptedData;
  144. this.isAuth = true;
  145. getApp().globalData.isAuth = true;
  146. getApp().globalData.globalAuth = true;
  147. this.loginUserInfo()
  148. },
  149. fail:(err)=> {
  150. getApp().globalData.isAuth = false;
  151. getApp().globalData.globalAuth = false;
  152. this.isAuth = false;
  153. }
  154. })
  155. },
  156. getPhoneNumber(e){
  157. let that = this;
  158. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  159. that.phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key)
  160. } else { //
  161. that.isNeedPhone = false;
  162. }
  163. },
  164. phoneRequest(myIv,myEncryptedData,sKey){
  165. let that = this;
  166. let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
  167. let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&source=user&action=phone&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
  168. uni.request({
  169. url:url,
  170. method: 'POST',
  171. header: {
  172. 'content-type': 'application/x-www-form-urlencoded'
  173. },
  174. data: {
  175. iv:myIv,
  176. sessionKey:sKey,
  177. encryptedData:myEncryptedData,
  178. openid:getApp().globalData.open_id
  179. },
  180. success: (res) => {
  181. console.log(res)
  182. if(res.data.code === 200){
  183. getApp().globalData.user_phone = res.data.data;
  184. this.userPhone = res.data.data.substr(0, 3) + '****' + res.data.data.substr(7) ;
  185. this.$refs.popup.close()
  186. uni.showTabBar({})
  187. }else {
  188. uni.showToast({
  189. title: res.data.msg,
  190. duration: 2500,
  191. icon: "none",
  192. });
  193. }
  194. },
  195. fail: () => {
  196. console.log("连接失败");
  197. }
  198. });
  199. },
  200. loginUserInfo(){
  201. let md5Sign = md5(
  202. "method=" +
  203. "user" +
  204. "&timestamp=" +
  205. getApp().globalData.globalTimestamp +
  206. "&secret=" +
  207. getApp().globalData.secret
  208. );
  209. let url =
  210. getApp().globalData.shareUrl +
  211. "api/api.php" +
  212. "?method=user&action=update&timestamp=" +
  213. getApp().globalData.globalTimestamp +
  214. "&sign=" +
  215. md5Sign;
  216. uni.request({
  217. url: url,
  218. method: "POST",
  219. header: {
  220. "content-type": "application/x-www-form-urlencoded",
  221. },
  222. data: {
  223. nickname:getApp().globalData.user_name,
  224. headimg:getApp().globalData.user_headUrl,
  225. openid:getApp().globalData.open_id
  226. },
  227. success: (res) => {
  228. if (res.data.code === 200) {
  229. }
  230. },
  231. fail: () => {
  232. console.log("连接失败");
  233. },
  234. });
  235. },
  236. goUpload(){
  237. let that = this;
  238. if(!that.isAuth){
  239. uni.showToast({
  240. title: "您还没有授权",
  241. duration: 2500,
  242. icon: "none",
  243. });
  244. return;
  245. }else {
  246. uni.navigateTo({
  247. url: "/pages/index/upload/upload",
  248. })
  249. }
  250. },
  251. getUserInfoData() {
  252. let md5Sign = md5(
  253. "method=" +
  254. "user" +
  255. "&timestamp=" +
  256. getApp().globalData.globalTimestamp +
  257. "&secret=" +
  258. getApp().globalData.secret
  259. );
  260. let url =
  261. getApp().globalData.shareUrl +
  262. "api/api.php" +
  263. "?method=user&action=info_by_openid&timestamp=" +
  264. getApp().globalData.globalTimestamp +
  265. "&sign=" +
  266. md5Sign;
  267. uni.request({
  268. url: url,
  269. method: "POST",
  270. header: {
  271. "content-type": "application/x-www-form-urlencoded",
  272. },
  273. data: {
  274. openid:getApp().globalData.open_id,
  275. },
  276. success: (res) => {
  277. if (res.data.code === 200) {
  278. if (res.data.data.nickname) {
  279. this.isAuth = true;
  280. this.userHeadImg = res.data.data.headimg;
  281. this.userNickName = res.data.data.nickname;
  282. if(res.data.data.phone){
  283. this.userPhone = res.data.data.phone.substr(0, 3) + '****' + res.data.data.phone.substr(7)
  284. this.getUserInfoBranch();
  285. }else {
  286. this.open()
  287. }
  288. getApp().globalData.globalAuth = true;
  289. getApp().globalData.user_name = res.data.data.nickname;
  290. getApp().globalData.user_headUrl = res.data.data.headimg;
  291. getApp().globalData.user_department = res.data.data.department;
  292. getApp().globalData.user_real_name = res.data.data.real_name;
  293. getApp().globalData.user_phone = res.data.data.phone;
  294. getApp().globalData.isAuth = true;
  295. this.isAuth = true;
  296. this.isNeedPhone = false;
  297. }else {
  298. this.open();
  299. this.isAuth = false;
  300. getApp().globalData.globalAuth = false;
  301. getApp().globalData.user_name = '';
  302. getApp().globalData.isAuth = false;
  303. this.isAuth = false;
  304. }
  305. }
  306. },
  307. fail: () => {
  308. console.log("连接失败");
  309. },
  310. });
  311. },
  312. getUserInfoBranch() {
  313. let md5Sign = md5(
  314. "method=" +
  315. "member" +
  316. "&timestamp=" +
  317. getApp().globalData.globalTimestamp +
  318. "&secret=" +
  319. getApp().globalData.secret
  320. );
  321. let url =
  322. getApp().globalData.shareUrl +
  323. "api/api.php" +
  324. "?method=member&action=my_branch&timestamp=" +
  325. getApp().globalData.globalTimestamp +
  326. "&sign=" +
  327. md5Sign;
  328. uni.request({
  329. url: url,
  330. method: "POST",
  331. header: {
  332. "content-type": "application/x-www-form-urlencoded",
  333. },
  334. data: {
  335. openid:getApp().globalData.open_id,
  336. },
  337. success: (res) => {
  338. if (res.data.code === 200) {
  339. this.userPosList = res.data.data;
  340. this.posLength = res.data.data.length;
  341. }
  342. },
  343. fail: () => {
  344. console.log("连接失败");
  345. },
  346. });
  347. },
  348. codeReg(strs){
  349. let reg = /\[(.*?)\]/gi;
  350. let str = strs;
  351. let tmp = str.match(reg) , result = '';
  352. if (tmp) {
  353. for (let i = 0; i < tmp.length; i++) {
  354. result = tmp[i].replace(reg, "$1")
  355. }
  356. } else {
  357. console.log("no match.");
  358. }
  359. console.log(result)
  360. this.getScanCode(result)
  361. },
  362. getScanCode(codeRes) {
  363. let md5Sign = md5(
  364. "method=" +
  365. "user" +
  366. "&timestamp=" +
  367. getApp().globalData.globalTimestamp +
  368. "&secret=" +
  369. getApp().globalData.secret
  370. );
  371. let url =
  372. getApp().globalData.shareUrl +
  373. "api/api.php" +
  374. "?method=user&action=qrcode_login&timestamp=" +
  375. getApp().globalData.globalTimestamp +
  376. "&sign=" +
  377. md5Sign;
  378. uni.request({
  379. url: url,
  380. method: "POST",
  381. header: {
  382. "content-type": "application/x-www-form-urlencoded",
  383. },
  384. data: {
  385. openid:getApp().globalData.open_id,
  386. qrcode:codeRes
  387. },
  388. success: (res) => {
  389. if (res.data.code === 200) {
  390. uni.showToast({
  391. title:res.data.msg,
  392. icon:'none'
  393. })
  394. } else {
  395. uni.showToast({
  396. title:res.data.msg,
  397. icon:'none'
  398. })
  399. }
  400. },
  401. fail: () => {
  402. console.log("连接失败");
  403. },
  404. });
  405. },
  406. goDetailFn(index, url) {
  407. let that = this;
  408. if(!that.isAuth){
  409. uni.showToast({
  410. title: "您还没有授权",
  411. duration: 2500,
  412. icon: "none",
  413. });
  414. return;
  415. }
  416. switch (index) {
  417. case 0: //扫码
  418. uni.scanCode({
  419. success: function (res) {
  420. console.log('条码类型:' + res.scanType);
  421. console.log('条码内容:' + res.result);
  422. that.codeReg(res.result)
  423. }
  424. });
  425. break;
  426. case 1: //个人信息
  427. uni.navigateTo({
  428. url,
  429. });
  430. break;
  431. case 2: //组织成员
  432. uni.navigateTo({
  433. url,
  434. });
  435. break;
  436. case 3: //后台登录
  437. uni.navigateTo({
  438. url,
  439. });
  440. break;
  441. case 4: //退出登录
  442. uni.showModal({
  443. title: "确定退出登录吗?",
  444. success(res) {
  445. if (res.confirm) {
  446. that.loginOut();
  447. } else if (res.cancel) {
  448. console.log("用户点击取消");
  449. }
  450. },
  451. });
  452. break;
  453. default:
  454. uni.navigateTo({
  455. url,
  456. });
  457. }
  458. },
  459. loginOut() {
  460. let md5Sign = md5(
  461. "method=" +
  462. "user" +
  463. "&timestamp=" +
  464. getApp().globalData.globalTimestamp +
  465. "&secret=" +
  466. getApp().globalData.secret
  467. );
  468. let url = getApp().globalData.shareUrl +
  469. "api/api.php" +
  470. "?method=user&action=logout&timestamp=" +
  471. getApp().globalData.globalTimestamp +
  472. "&sign=" +
  473. md5Sign;
  474. uni.request({
  475. url: url,
  476. method: "POST",
  477. header: {
  478. "content-type": "application/x-www-form-urlencoded",
  479. },
  480. data: {
  481. openid: getApp().globalData.open_id,
  482. },
  483. success: (res) => {
  484. if (res.data.code === 200) {
  485. let that = this;
  486. that.isAuth = false;
  487. getApp().globalData.isAuth = false;
  488. getApp().globalData.user_headUrl = "";
  489. getApp().globalData.user_name = "";
  490. getApp().globalData.user_phone = "";
  491. this.userPhone = '';
  492. //this.list[3].isShow = false;
  493. //this.$forceUpdate();
  494. uni.showToast({
  495. title: "退出登录成功",
  496. duration: 2500,
  497. icon: "none",
  498. success() {
  499. that.open()
  500. }
  501. });
  502. }
  503. },
  504. fail: () => {
  505. console.log("连接失败");
  506. },
  507. });
  508. },
  509. },
  510. };
  511. </script>
  512. <style lang="scss" scoped>
  513. .content {
  514. display: flex;
  515. flex-direction: column;
  516. .self-inf {
  517. position: relative;
  518. height: 240rpx;
  519. width: 100%;
  520. // display: flex;
  521. // margin-bottom: 80rpx;
  522. background-color: #c2e3e6;
  523. // border-radius: 0rpx 0rpx 100% 100%;
  524. .img-name-box {
  525. height: 150rpx;
  526. margin-top: 20rpx;
  527. margin-bottom: 20rpx;
  528. display: flex;
  529. align-items: center;
  530. width: 85%;
  531. .auth-btn {
  532. margin-left: 30rpx;
  533. margin-top: 20rpx;
  534. font-size: 28rpx;
  535. background-color: #02a7f0;
  536. color: #fff;
  537. }
  538. .heade-img {
  539. z-index: 1;
  540. width: 100rpx;
  541. height: 100rpx;
  542. border-radius: 50%;
  543. // margin-left: 80rpx;
  544. }
  545. }
  546. .bg-img {
  547. z-index: -1;
  548. position: absolute;
  549. width: 100%;
  550. height: 100%;
  551. // border-radius: 0rpx 0rpx 70rpx 70rpx;
  552. }
  553. .nickname {
  554. font-weight: 600;
  555. font-size: 28rpx;
  556. margin-left: 30rpx;
  557. margin-top: 20rpx;
  558. color: #555;
  559. letter-spacing: 1rpx;
  560. }
  561. }
  562. .options {
  563. padding: 80rpx 70rpx 20rpx 70rpx;
  564. z-index: 99;
  565. position: relative;
  566. .options-item {
  567. background-color: #fff;
  568. display: flex;
  569. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  570. border-radius: 32rpx;
  571. margin-top: 30rpx;
  572. height: 75px;
  573. align-items: center;
  574. .img-box {
  575. margin-left: 40rpx;
  576. .options-item-img {
  577. width: 56rpx;
  578. height: 56rpx;
  579. }
  580. }
  581. .options-item-name {
  582. margin-left: 40rpx;
  583. font-weight: 600;
  584. font-size: 30rpx;
  585. margin-bottom: 10rpx;
  586. }
  587. }
  588. }
  589. }
  590. .auth-box {
  591. display: flex;
  592. background-color: #fff;
  593. height: 500rpx;
  594. width: 600rpx;
  595. border-radius: 10rpx;
  596. button {
  597. height:100rpx;
  598. font-size: 26rpx;
  599. };
  600. }
  601. .fontGrey {
  602. color: $uni-text-color-grey;
  603. }
  604. .antu-box {
  605. display: flex;
  606. flex-direction: column;
  607. align-items: center;
  608. background: #fff;
  609. border-radius: 10rpx;
  610. position: relative;
  611. z-index: 99;
  612. top: 25px;
  613. width: 80%;
  614. left: 10%;
  615. color: #555;
  616. box-shadow: 0px 2px 16px rgba(0, 0, 0, 0.2);
  617. }
  618. .submit-btn {
  619. color: white;
  620. font-weight: normal;
  621. width: 70%;
  622. border-radius: 20rpx;
  623. background-color: #02a7f0;
  624. margin: 50rpx auto;
  625. }
  626. .org-info-box {
  627. display: flex;
  628. justify-content: space-evenly;
  629. height: 80rpx;
  630. align-items: center;
  631. width: 100%;
  632. border-top: 1px solid #d4d4d4;
  633. color: #555;
  634. font-size: 28rpx;
  635. background: #fff;
  636. }
  637. .org-info {
  638. width: 50%;
  639. padding-left: 10%;
  640. }
  641. .org-line {
  642. width: 1px;
  643. height: 82rpx;
  644. background: #d4d4d4;
  645. }
  646. .auth-pop{
  647. background-color: #fff;
  648. text-align: center;
  649. display: flex;
  650. flex-direction: column;
  651. justify-content: center;
  652. align-items: center;
  653. width: 75%;
  654. margin: 0 auto;
  655. border-radius: 10rpx;
  656. padding: 20rpx;
  657. }
  658. .auth-pop image{
  659. width: 200upx;
  660. height: 200upx;
  661. margin-top: 10%;
  662. }
  663. .auth-pop view {
  664. // display: flex;
  665. // width: 490upx;
  666. // justify-content: space-between;
  667. }
  668. .auth-title {
  669. font-size: 32upx;
  670. }
  671. .auth-content {
  672. font-size: 26upx;
  673. color: #a7aaa9;
  674. }
  675. .allow {
  676. background-color: #27BCEF;
  677. margin: 20rpx 0 75rpx;
  678. text-align: center;
  679. vertical-align: middle;
  680. touch-action: manipulation;
  681. cursor: pointer;
  682. background-image: none;
  683. white-space: nowrap;
  684. user-select: none;
  685. font-size: 14px;
  686. border: 0 !important;
  687. position: relative;
  688. text-decoration: none;
  689. height: 44px;
  690. width: 250rpx;
  691. line-height: 44px;
  692. box-shadow: inset 0 0 0 1px #27BCEF;
  693. background: #fff !important;
  694. color: #27BCEF !important;
  695. display: inline-block;
  696. border-radius: 10rpx;
  697. }
  698. .refuse {
  699. background-color: #19be6b;
  700. margin: 20rpx 20rpx 200rpx 20rpx;
  701. text-align: center;
  702. vertical-align: middle;
  703. touch-action: manipulation;
  704. cursor: pointer;
  705. background-image: none;
  706. white-space: nowrap;
  707. user-select: none;
  708. font-size: 14px;
  709. border: 0 !important;
  710. position: relative;
  711. text-decoration: none;
  712. height: 44px;
  713. width: 250rpx;
  714. line-height: 44px;
  715. box-shadow: inset 0 0 0 1px #8a8a8a;
  716. background: #fff !important;
  717. color: #8a8a8a !important;
  718. display: inline-block;
  719. border-radius: 10rpx;
  720. }
  721. .margin-top-3{
  722. margin-top: 10%;
  723. }
  724. .paddingTop80 {
  725. padding-top:160rpx;
  726. }
  727. </style>