index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <view class="container">
  3. <view class="banner">
  4. <image src="https://wanzai-1306339220.cos.ap-shanghai.myqcloud.com/excelModel/banner2x.png" mode=""></image>
  5. </view>
  6. <view class="nav">
  7. <view class="menu">
  8. <navigator :url="'/pages/reshui/reshui'" open-type="navigate" class="menu_item">
  9. <image src="../../static/images/shower2x.png" mode=""></image>
  10. <text>墨轩湖1-16栋</text>
  11. <text>洗浴</text>
  12. </navigator>
  13. <!-- <navigator :url="'/pagesElectric/jiaofei/jiaofei?o=index'" open-type="navigate" class="menu_item">
  14. <image src="../../static/images/recharge2x.png" mode=""></image>
  15. <text>墨轩湖1-12栋</text>
  16. <text>水电充值</text>
  17. </navigator> -->
  18. <navigator :url="'/pagesAir/shareAir/shareAir'" open-type="navigate" class="menu_item">
  19. <image src="../../static/images/air.png" mode=""></image>
  20. <text>共享空调</text>
  21. </navigator>
  22. <navigator :url="'/pagesRepairs/index/index'" open-type="navigate" class="menu_item">
  23. <image src="../../static/images/repairs.png" mode=""></image>
  24. <text>校园报修</text>
  25. </navigator>
  26. <!-- <navigator :url="'/pagesBus/bus/bus'" open-type="navigate" class="menu_item">
  27. <image src="../../static/images/bus.png" mode=""></image>
  28. <text>校车预约</text>
  29. </navigator> -->
  30. <navigator :url="'/pagesClockIn/index/index'" open-type="navigate" class="menu_item">
  31. <image src="../../static/images/clockIn.png" mode=""></image>
  32. <text>校园打卡</text>
  33. </navigator>
  34. <!-- <navigator :url="'/pages/web/web'" open-type="navigate" class="menu_item">
  35. <image src="../../static/images/1.png" mode=""></image>
  36. <text>课表查询</text>
  37. </navigator> -->
  38. <!-- <navigator :url="'/pagesClockIn/money/money'" open-type="navigate" class="menu_item">
  39. <image src="../../static/images/money.png" mode=""></image>
  40. <text>学费缴纳</text>
  41. </navigator> -->
  42. <view class="menu_item">
  43. <text></text>
  44. </view>
  45. <view class="menu_item">
  46. <text></text>
  47. </view>
  48. <!-- <view class="menu_item">
  49. <text></text>
  50. </view> -->
  51. </view>
  52. </view>
  53. <view v-if="showLogin">
  54. <login
  55. :ocode="ocode"
  56. :appkey="appkey"
  57. scope="snsapi_userinfo"
  58. :visible="visible"
  59. @success="login_success_callback"
  60. @cancel="login_cancel_callback"
  61. @fail="login_fail_callback"
  62. />
  63. </view>
  64. <Popup :showPopup="showPopup" @close="showPopup = false">
  65. <view class="pupup-content">
  66. <text class="pupup-title">请截屏,再识别二维码领取校园卡</text>
  67. <image src="../../static/images/qr.jpg" mode="aspectFill" class="pupup-img"></image>
  68. </view>
  69. </Popup>
  70. </view>
  71. </template>
  72. <script>
  73. import Popup from '@/components/Popup.vue'
  74. export default {
  75. components: {
  76. Popup
  77. },
  78. data() {
  79. return {
  80. ceshi: 'code',
  81. huanjing: '部署环境', // 部署环境是key,用来获取环境
  82. visible: false, // 是否授权可见
  83. showLogin: true, // 是否启动授权
  84. appkey: '3183DC96A6DABA8D', // 商户appkey
  85. appid: 'wxd6f090391d410534', // 获取用户信息
  86. ocode: '1015730314', // 获取用户信息
  87. app_secret: '05742955578EC5BD29B7BC4CAC5AFACA', // 获取用户信息
  88. userinfo: '', // 用户信息
  89. showQR_code: false, // 显示校园卡二维码
  90. validation_failed: false, // 验证失败
  91. validation_times: 0, // 授权次数
  92. from: 0, // 跳转参数
  93. execed_onload: false,
  94. showPopup: false
  95. }
  96. },
  97. onLoad(options) {
  98. // console.log(options)
  99. // 测试环境
  100. if (typeof options.from != 'undefined') {
  101. this.from = options.from
  102. }
  103. // 检查是否存在用户信息
  104. this.has_user_info()
  105. // 是否是测试环境,查询数据接口中参数的值决定,方便以后测试
  106. this.isTestEnvironment()
  107. this.execed_onload = true
  108. },
  109. onShow() {
  110. if (!this.execed_onload) {
  111. // 检查是否存在用户信息
  112. this.has_user_info()
  113. }
  114. },
  115. methods: {
  116. /**
  117. * 控制环境,test为true测试环境,false则是正式环境
  118. */
  119. async isTestEnvironment() {
  120. const res = await this.$myRequest({
  121. host: this.ceshi,
  122. url: '/HotWaters/conEnvi.action',
  123. method: 'POST',
  124. header: {
  125. 'content-type': 'application/x-www-form-urlencoded'
  126. },
  127. data: {
  128. name: this.huanjing
  129. }
  130. })
  131. // console.log(res);
  132. if (res.data.mess == '返回成功') {
  133. // value为0 测试环境, 为1 部署环境;amount限制启动金额
  134. this.$store.state.amount = res.data.data[0].amount
  135. if (res.data.data[0].value == 0) {
  136. // 测试模式
  137. this.$store.state.test = true
  138. } else if (res.data.data[0].value == 2) {
  139. // 系统正在维护...
  140. this.$store.state.test = 'weihuzhong'
  141. uni.showModal({
  142. title: '提示信息',
  143. content: '系统维护中...\r\n暂时请不要使用!\r\n避免造成不必要的损失!',
  144. showCancel: false
  145. })
  146. } else {
  147. // 正式模式
  148. this.$store.state.test = false
  149. }
  150. } else {
  151. uni.showToast({
  152. title: res.data.mess,
  153. icon: 'success'
  154. })
  155. }
  156. },
  157. /**
  158. * 是否有用户信息
  159. */
  160. has_user_info() {
  161. try {
  162. // console.log(111111);
  163. const value = uni.getStorageSync('userinfo_storage_key')
  164. // console.log(value);
  165. if (value == '') {
  166. this.showLogin = true
  167. this.visible = true
  168. } else {
  169. this.showLogin = false
  170. this.userinfo = value
  171. this.$store.state.userInfo = this.userinfo
  172. }
  173. } catch (e) {
  174. // console.log(e)
  175. uni.showToast({
  176. title: '异常:' + e,
  177. duration: 3000
  178. })
  179. }
  180. },
  181. /**
  182. * 授权登陆取消回调
  183. */
  184. login_cancel_callback() {
  185. this.reauthorization()
  186. },
  187. /**
  188. * 重新授权
  189. */
  190. reauthorization() {
  191. this.validation_times = this.validation_times + 1
  192. if (this.validation_times >= 2) {
  193. this.login_fail_callback()
  194. } else {
  195. try {
  196. // uni.removeStorageSync('userinfo_storage_key')
  197. setTimeout(() => {
  198. this.showLogin = false
  199. this.userinfo = {}
  200. }, 30)
  201. setTimeout(() => {
  202. this.showLogin = true
  203. this.visible = true
  204. }, 30)
  205. } catch (e) {
  206. console.log(e)
  207. }
  208. }
  209. },
  210. /**
  211. * 授权登陆取消回调
  212. */
  213. login_fail_callback() {
  214. var _this = this
  215. _this.userinfo = {}
  216. if (!_this.validation_failed) {
  217. _this.validation_failed = false
  218. uni.showModal({
  219. title: '提示',
  220. content: '授权:请先领取校园卡、并激活!',
  221. // cancelText: '取消',
  222. confirmText: '领取',
  223. success: (res1) => {
  224. if (res1.confirm) {
  225. // 截屏,用户利用微信识别二维码添加校园卡、激活
  226. _this.showPopup = true
  227. } else if (res1.cancel) {
  228. // console.log('用户点击取消');
  229. // uni.showToast({
  230. // icon: 'none',
  231. // title: '10秒后自动隐藏二维码,可重新授权调起!',
  232. // duration: 1000,
  233. // success: (com) => {
  234. // this.showQR_code = true
  235. // setTimeout(() => {
  236. // this.showQR_code = false
  237. // }, 10000)
  238. // }
  239. // });
  240. }
  241. }
  242. })
  243. }
  244. },
  245. /**
  246. * 授权登陆成功回调
  247. */
  248. login_success_callback: function ({ detail }) {
  249. const { wxcode = '' } = detail
  250. this.validation_failed = false
  251. // 屏蔽用户操作
  252. uni.showLoading({
  253. title: '获取数据中…',
  254. mask: true
  255. })
  256. // 通过wxcode换取access_token
  257. this.get_access_token(wxcode)
  258. },
  259. /**
  260. * 通过wxcode换取access_token
  261. */
  262. async get_access_token(param_wxcode) {
  263. const res = await this.$myRequest({
  264. host: 'wecard',
  265. url: '/connect/oauth2/token',
  266. method: 'POST',
  267. header: {
  268. 'content-type': 'application/json'
  269. },
  270. data: {
  271. wxcode: param_wxcode,
  272. app_key: this.appkey,
  273. app_secret: this.app_secret,
  274. grant_type: 'authorization_code',
  275. redirect_uri: 'mnp://' + this.appid
  276. }
  277. })
  278. if (res.data.refresh_token == '' || typeof res.data.refresh_token == 'undefined') {
  279. uni.hideLoading()
  280. uni.showToast({
  281. title: '未获得token'
  282. })
  283. } else {
  284. // 通过access_token换取用户信息
  285. this.get_user_info(res.data.access_token)
  286. }
  287. },
  288. /**
  289. * 通过access_token换取用户信息
  290. */
  291. async get_user_info(param_access_token) {
  292. const res = await this.$myRequest({
  293. host: 'wecard',
  294. url: '/connect/oauth/get-user-info',
  295. method: 'POST',
  296. header: {
  297. 'content-type': 'application/json'
  298. },
  299. data: {
  300. access_token: param_access_token
  301. }
  302. })
  303. // console.log(res);
  304. if (res.data.errcode == 0 && res.data.errmsg == 'OK') {
  305. try {
  306. this.userinfo = res.data
  307. this.$store.state.userInfo = res.data
  308. // 获取code,然后去检查是否存在数据库中
  309. this.getCode()
  310. } catch (e) {
  311. uni.hideLoading()
  312. console.log(e)
  313. }
  314. } else {
  315. uni.hideLoading()
  316. uni.showToast({
  317. title: '未获得用户信息,请领取校园卡并激活',
  318. duration: 3000
  319. })
  320. }
  321. },
  322. /**
  323. * 获得code
  324. */
  325. getCode() {
  326. var _this = this
  327. uni.login({
  328. success: (res) => {
  329. // console.log('reshui', res);
  330. if (res.code) {
  331. // 检查用户是否存在第三方库
  332. _this.chk_user_is_in_db(res.code)
  333. } else {
  334. uni.hideLoading()
  335. uni.showToast({
  336. title: res.errMsg,
  337. icon: 'none'
  338. })
  339. }
  340. },
  341. fail() {
  342. uni.hideLoading()
  343. }
  344. })
  345. },
  346. /**
  347. * 检查数据库中是否有该用户信息
  348. */
  349. async chk_user_is_in_db(param_code) {
  350. var _this = this
  351. const res = await _this.$myRequest({
  352. // host: 'local',
  353. host: _this.ceshi,
  354. url: '/HotWaters/wpopenid.action',
  355. method: 'POST',
  356. header: {
  357. 'content-type': 'application/x-www-form-urlencoded'
  358. },
  359. data: {
  360. userinfo: JSON.stringify(_this.userinfo),
  361. code: param_code
  362. }
  363. })
  364. // console.log(res);
  365. if (res.data.code == 0 || res.data.code == 100) {
  366. // 存储用户信息
  367. uni.setStorageSync('userinfo_storage_key', _this.userinfo)
  368. uni.hideLoading()
  369. // 提示授权成功
  370. uni.showToast({
  371. icon: 'success',
  372. title: '授权成功',
  373. duration: 800,
  374. success: (res) => {
  375. if (_this.from != 0 || _this.from != '0') {
  376. // 页面跳转回去
  377. uni.setStorageSync('navigateBack', 1)
  378. uni.navigateBack({
  379. delta: 1
  380. })
  381. }
  382. }
  383. })
  384. } else {
  385. uni.hideLoading()
  386. uni.showToast({
  387. icon: 'none',
  388. title: '授权失败:' + res.data.msg,
  389. success: (res) => {}
  390. })
  391. }
  392. }
  393. }
  394. }
  395. </script>
  396. <style scoped lang="scss">
  397. .container {
  398. display: flex;
  399. flex-direction: column;
  400. width: 750rpx;
  401. font-family: Microsoft YaHei-3970(82674968);
  402. color: #333333;
  403. .banner {
  404. width: 100%;
  405. height: 360rpx;
  406. image {
  407. width: 100%;
  408. height: 100%;
  409. }
  410. }
  411. .nav {
  412. position: relative;
  413. width: 100%;
  414. background-color: #eee;
  415. box-sizing: border-box;
  416. .menu {
  417. display: flex;
  418. flex-wrap: wrap;
  419. width: 750rpx;
  420. box-sizing: border-box;
  421. .menu_item {
  422. display: flex;
  423. flex-direction: column;
  424. flex: 1 0 30%;
  425. text-align: center;
  426. padding: 30rpx 0 39rpx;
  427. font-family: Microsoft YaHei-3970(82674968);
  428. color: #333333;
  429. background-color: #fff;
  430. margin: 1rpx;
  431. image {
  432. width: 90rpx;
  433. height: 90rpx;
  434. margin: 0 auto;
  435. }
  436. text {
  437. box-sizing: border-box;
  438. padding: 0 10rpx;
  439. margin-top: 16rpx;
  440. line-height: 36rpx;
  441. font-size: 30rpx;
  442. color: #333333;
  443. }
  444. }
  445. }
  446. }
  447. .pupup-content {
  448. display: flex;
  449. flex-direction: column;
  450. justify-content: center;
  451. align-items: center;
  452. height: 100%;
  453. .pupup-title {
  454. padding-bottom: 20rpx;
  455. }
  456. .pupup-img {
  457. height: 90%;
  458. }
  459. }
  460. }
  461. </style>