index.vue 9.6 KB

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