App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <script>
  2. import md5 from '@/common/md5.js';
  3. export default {
  4. globalData: {
  5. shareUrl: 'https://xnh.xazhima.com/prod-api/wap/business/weixin/',
  6. globalTimestamp: Date.now().toString(),
  7. secret: 'AirQK_weichat_app_zhima',
  8. selectedIndex: 0,
  9. isSider: false,
  10. user_id: '',
  11. open_id: '',
  12. user_status: '',
  13. user_name: '',
  14. user_phone: '',
  15. user_headUrl: '',
  16. globalAuth: false,
  17. session_key: '',
  18. isAndroid: false,
  19. user_department: '',
  20. user_real_name: ''
  21. },
  22. onLaunch: function () {
  23. console.log('App Launch');
  24. // let equType = uni.getSystemInfoSync().platform;
  25. //  switch(equType){
  26. //     case 'android':
  27. //        console.log('运行Android上')
  28. // setTimeout(()=>{
  29. // getApp().globalData.isAndroid = true
  30. // },100)
  31. //        break;
  32. //     case 'ios':
  33. //        console.log('运行iOS上');
  34. //        break;
  35. //     default:
  36. //        console.log('运行在开发者工具上')
  37. //        break;
  38. // }
  39. this.loginLoad();
  40. },
  41. onShow: function () {
  42. console.log('App Show');
  43. // uni.hideTabBar({})
  44. },
  45. onHide: function () {
  46. console.log('App Hide');
  47. },
  48. methods: {
  49. loginLoad() {
  50. let that = this;
  51. uni.login({
  52. success(res) {
  53. that.loginRequest(res.code);
  54. }
  55. });
  56. },
  57. loginRequest(codeRes) {
  58. let that = this;
  59. let url = getApp().globalData.shareUrl + 'login/' + codeRes;
  60. uni.request({
  61. url: url,
  62. method: 'GET',
  63. header: {
  64. 'content-type': 'application/x-www-form-urlencoded'
  65. },
  66. success: (res) => {
  67. console.log(res);
  68. if (res.data.code === 200) {
  69. uni.setStorageSync('openid', res.data.data.openid);
  70. getApp().globalData.open_id = res.data.data.openid;
  71. getApp().globalData.session_key = res.data.data.session_key;
  72. that.$isResolve();
  73. // uni.hideLoading()
  74. }
  75. },
  76. fail: () => {
  77. console.log('连接失败');
  78. }
  79. });
  80. },
  81. getPhoneNumber(e){
  82. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  83. console.log(e.detail);
  84. getApp().phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key);
  85. return true;
  86. } else { //
  87. return false;
  88. }
  89. },
  90. phoneRequest(myIv,myEncryptedData,sKey){
  91. let url = getApp().globalData.shareUrl + '/phone';
  92. //let url = "https://192.168.0.106:1024/dev-api/wap/business/weixin/phone";
  93. uni.request({
  94. url:url,
  95. method: 'POST',
  96. header: {
  97. 'content-type': 'application/x-www-form-urlencoded'
  98. },
  99. data: {
  100. iv:myIv,
  101. sessionKey:sKey,
  102. encryptedData:myEncryptedData,
  103. openid:getApp().globalData.open_id
  104. },
  105. success: (res) => {
  106. console.log(res)
  107. if(res.data.code === 200){
  108. getApp().globalData.user_phone = res.data.data;
  109. if (res.data.data != ""){
  110. getApp().globalData.globalAuth = true;
  111. }
  112. }
  113. },
  114. fail: () => {
  115. console.log("连接失败");
  116. }
  117. });
  118. },
  119. }
  120. };
  121. </script>
  122. <style lang="scss">
  123. /*每个页面公共css */
  124. @import '@/common/uni.css';
  125. page {
  126. height: 100%;
  127. background: #f3f3f3;
  128. &:before {
  129. content: '';
  130. position: fixed;
  131. left: 0;
  132. right: 0;
  133. top: 0;
  134. z-index: 1;
  135. height: 1rpx;
  136. background: #e0e0e0;
  137. }
  138. }
  139. button::after {
  140. display: none;
  141. }
  142. .c-abnor {
  143. position: fixed;
  144. left: 50%;
  145. top: 50%;
  146. transform: translate(-50%, -50%);
  147. display: flex;
  148. flex-direction: column;
  149. white-space: nowrap;
  150. align-items: center;
  151. font-size: 27.47rpx;
  152. color: #999;
  153. .icon {
  154. width: 137.36rpx;
  155. height: 137.36rpx;
  156. margin-bottom: 41.21rpx;
  157. }
  158. }
  159. * {
  160. touch-action: none;
  161. }
  162. .display-flex-start {
  163. display: flex;
  164. align-items: center;
  165. }
  166. .display-flex-center {
  167. display: flex;
  168. justify-content: center;
  169. align-items: center;
  170. }
  171. .display-flex-end {
  172. display: flex;
  173. justify-content: flex-end;
  174. align-items: center;
  175. }
  176. .display-between {
  177. display: flex;
  178. justify-content: space-between;
  179. }
  180. .display-around {
  181. display: flex;
  182. justify-content: space-around;
  183. }
  184. .display-between-column {
  185. display: flex;
  186. flex-direction: column;
  187. justify-content: space-between;
  188. }
  189. .display-around-column {
  190. display: flex;
  191. flex-direction: column;
  192. justify-content: space-around;
  193. }
  194. .display-evenly-column {
  195. display: flex;
  196. flex-direction: column;
  197. justify-content: space-evenly;
  198. }
  199. .display-wrap {
  200. flex-wrap: wrap;
  201. }
  202. .items-center {
  203. align-items: center;
  204. }
  205. .margin-top-10 {
  206. margin-top: 10%;
  207. }
  208. .shareParent {
  209. width: 100%;
  210. height: 100%;
  211. position: fixed;
  212. }
  213. .margin-right-10 {
  214. margin-right: 10rpx;
  215. }
  216. .margin-top-1 {
  217. margin-top: 1%;
  218. }
  219. .margin-right-0 {
  220. margin-right: 0 !important;
  221. }
  222. .color-666 {
  223. color: #666666;
  224. }
  225. .color-999 {
  226. color: #999;
  227. }
  228. .width-55 {
  229. width: 55%;
  230. }
  231. </style>