App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <script>
  2. import md5 from '@/common/md5.js';
  3. export default {
  4. globalData: {
  5. //shareUrl: "https://heater.xazhima.com/", 测试地址
  6. shareUrl:"https://h.xayuanju.com/",
  7. globalTimestamp: Date.now().toString(),
  8. secret: "Heater_weichat_app_zhima",
  9. selectedIndex:0,
  10. isSider:false,
  11. user_id: '',
  12. open_id:'',
  13. //open_id:"oX46e5ImwFndnH442HW6Yt7W9Mck",//测试使用 替换正确appId后默认为空
  14. user_status:'',
  15. user_name:'',
  16. user_phone:'',
  17. user_headUrl:'',
  18. globalAuth:false,
  19. session_key: '',
  20. contact_name:'',
  21. company_name:'',
  22. company_logo:'',
  23. isAndroid:false,
  24. nowTime:'',
  25. statusObj:{
  26. '0':'未缴费',
  27. '1':'已缴费',
  28. '2':'空置已缴费',
  29. '3':'空置转全额'
  30. },
  31. statusColor:{
  32. '0':'#D9001B',
  33. '1':'#70B603',
  34. '2':'#4B7902',
  35. '3':'#BFBF00',
  36. }
  37. },
  38. onLaunch: function () {
  39. console.log("App Launch");
  40. // let equType = uni.getSystemInfoSync().platform;
  41. //  switch(equType){
  42. //     case 'android':
  43. //        console.log('运行Android上')
  44. // setTimeout(()=>{
  45. // getApp().globalData.isAndroid = true
  46. // },100)
  47. //        break;
  48. //     case 'ios':
  49. //        console.log('运行iOS上');
  50. //        break;
  51. //     default:
  52. //        console.log('运行在开发者工具上')
  53. //        break;
  54. // }
  55. this.loginLoad();
  56. },
  57. onShow: function () {
  58. console.log("App Show");
  59. uni.hideTabBar({})
  60. },
  61. onHide: function () {
  62. console.log("App Hide");
  63. },
  64. methods:{
  65. getNowTime(){
  66. let time = new Date(Date.now());
  67. const y = time.getFullYear();
  68. const m =
  69. time.getMonth() + 1 < 10
  70. ? "0" + (time.getMonth() + 1)
  71. : time.getMonth() + 1;
  72. const d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
  73. // const h = time.getHours()
  74. // const mm = time.getMinutes();
  75. // const s = time.getSeconds();
  76. return y + "-" + m + "-" + d;
  77. },
  78. loginLoad(){
  79. let that = this;
  80. uni.login({
  81. success(res) {
  82. that.loginRequest(res.code)
  83. }
  84. })
  85. },
  86. makeApiUrl(method,source,action){
  87. let timestamp = Date.now().toString();
  88. let md5Sign = md5("method="+method+"&timestamp="+timestamp+"&secret="+getApp().globalData.secret);
  89. let url = getApp().globalData.shareUrl+'api/api.php'+'?method='+method+'&source='+source+'&action='+action+'&timestamp='+timestamp +'&sign='+md5Sign;
  90. return url;
  91. },
  92. MD5(str){
  93. let md5str = md5(str);
  94. return md5str.toUpperCase();
  95. },
  96. randomStr(len){
  97. let str = '';
  98. let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  99. for (let i = 0; i < len; i++){
  100. str += chars.charAt(Math.random() * chars.length);
  101. }
  102. return str;
  103. },
  104. loginRequest(codeRes){
  105. let md5Sign = md5("method="+'user'+"&timestamp="+getApp().globalData.globalTimestamp+"&secret="+getApp().globalData.secret)
  106. let url = getApp().globalData.shareUrl+'api/api.php'+'?method=user&source=user&action=login&timestamp='+getApp().globalData.globalTimestamp +'&sign='+md5Sign
  107. uni.request({
  108. url:url,
  109. method: 'POST',
  110. header: {
  111. 'content-type': 'application/x-www-form-urlencoded'
  112. },
  113. data: {
  114. code:codeRes
  115. },
  116. success: (res) => {
  117. console.log(res)
  118. if(res.data.code === 200){
  119. getApp().globalData.session_key = res.data.data.session_key;
  120. getApp().globalData.open_id = res.data.data.openid;
  121. getApp().globalData.user_status = res.data.data.status;
  122. getApp().globalData.user_phone = res.data.data.phone;
  123. getApp().globalData.nowTime = this.getNowTime();
  124. uni.setStorageSync('openId', res.data.data.openid);
  125. // uni.hideLoading()
  126. }
  127. },
  128. fail: () => {
  129. console.log("连接失败");
  130. }
  131. });
  132. },
  133. }
  134. };
  135. </script>
  136. <style lang="scss">
  137. /*每个页面公共css */
  138. @import url("/components/gaoyia-parse/parse.css");
  139. @import '@/common/uni.css';
  140. page {
  141. height: 100%;
  142. }
  143. .display-flex-start {
  144. display: flex;
  145. align-items: center;
  146. }
  147. .display-flex-end {
  148. display: flex;
  149. justify-content: flex-end;
  150. align-items: center;
  151. }
  152. .display-between {
  153. display: flex;
  154. justify-content: space-between;
  155. }
  156. .display-around {
  157. display: flex;
  158. justify-content: space-around;
  159. }
  160. .display-between-column {
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: space-between;
  164. }
  165. .display-around-column {
  166. display: flex;
  167. flex-direction: column;
  168. justify-content: space-around;
  169. }
  170. .display-wrap {
  171. display: flex;
  172. flex-wrap: wrap;
  173. }
  174. .items-center {
  175. align-items: center;
  176. }
  177. .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
  178. max-height: 50%!important;
  179. }
  180. </style>