App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. isAuth : false,
  20. session_key: '',
  21. contact_name:'',
  22. company_name:'',
  23. company_logo:'',
  24. isAndroid:false,
  25. nowTime:'',
  26. statusObj:{
  27. '0':'未缴费',
  28. '1':'已缴费',
  29. '2':'空置已缴费',
  30. '3':'空置转全额'
  31. },
  32. statusColor:{
  33. '0':'#D9001B',
  34. '1':'#70B603',
  35. '2':'#4B7902',
  36. '3':'#BFBF00',
  37. }
  38. },
  39. onLaunch: function () {
  40. console.log("App Launch");
  41. // let equType = uni.getSystemInfoSync().platform;
  42. //  switch(equType){
  43. //     case 'android':
  44. //        console.log('运行Android上')
  45. // setTimeout(()=>{
  46. // getApp().globalData.isAndroid = true
  47. // },100)
  48. //        break;
  49. //     case 'ios':
  50. //        console.log('运行iOS上');
  51. //        break;
  52. //     default:
  53. //        console.log('运行在开发者工具上')
  54. //        break;
  55. // }
  56. this.loginLoad();
  57. },
  58. onShow: function () {
  59. console.log("App Show");
  60. uni.hideTabBar({})
  61. },
  62. onHide: function () {
  63. console.log("App Hide");
  64. },
  65. methods:{
  66. getNowTime(){
  67. let time = new Date(Date.now());
  68. const y = time.getFullYear();
  69. const m =
  70. time.getMonth() + 1 < 10
  71. ? "0" + (time.getMonth() + 1)
  72. : time.getMonth() + 1;
  73. const d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
  74. // const h = time.getHours()
  75. // const mm = time.getMinutes();
  76. // const s = time.getSeconds();
  77. return y + "-" + m + "-" + d;
  78. },
  79. loginLoad(){
  80. let that = this;
  81. uni.login({
  82. success(res) {
  83. that.loginRequest(res.code)
  84. }
  85. })
  86. },
  87. makeApiUrl(method,source,action){
  88. let timestamp = Date.now().toString();
  89. let md5Sign = md5("method="+method+"&timestamp="+timestamp+"&secret="+getApp().globalData.secret);
  90. let url = getApp().globalData.shareUrl+'api/api.php'+'?method='+method+'&source='+source+'&action='+action+'&timestamp='+timestamp +'&sign='+md5Sign;
  91. return url;
  92. },
  93. MD5(str){
  94. let md5str = md5(str);
  95. return md5str.toUpperCase();
  96. },
  97. randomStr(len){
  98. let str = '';
  99. let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  100. for (let i = 0; i < len; i++){
  101. str += chars.charAt(Math.random() * chars.length);
  102. }
  103. return str;
  104. },
  105. loginRequest(codeRes){
  106. let url = getApp().makeApiUrl("user",'user','login');
  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. if (res.data.data.phone === ''){
  125. //必须有手机号才算登录成功,系统才可用。
  126. // console.log("res.data.data.phone="+res.data.data.phone);
  127. getApp().globalData.isAuth = false;
  128. }
  129. else{
  130. getApp().globalData.isAuth = true;
  131. }
  132. uni.setStorageSync('openId', res.data.data.openid);
  133. // uni.hideLoading()
  134. }
  135. },
  136. fail: () => {
  137. console.log("连接失败");
  138. }
  139. });
  140. },
  141. getPhoneNumber(e){
  142. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  143. console.log(e.detail);
  144. getApp().phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key);
  145. return true;
  146. } else { //
  147. return false;
  148. }
  149. },
  150. phoneRequest(myIv,myEncryptedData,sKey){
  151. let url = getApp().makeApiUrl('user','user','phone');
  152. uni.request({
  153. url:url,
  154. method: 'POST',
  155. header: {
  156. 'content-type': 'application/x-www-form-urlencoded'
  157. },
  158. data: {
  159. iv:myIv,
  160. sessionKey:sKey,
  161. encryptedData:myEncryptedData,
  162. openId:getApp().globalData.open_id
  163. },
  164. success: (res) => {
  165. console.log(res)
  166. if(res.data.code === 200){
  167. getApp().globalData.user_phone = res.data.data;
  168. if (res.data.data != ""){
  169. getApp().globalData.isAuth = true;
  170. }
  171. }
  172. },
  173. fail: () => {
  174. console.log("连接失败");
  175. }
  176. });
  177. },
  178. }
  179. };
  180. </script>
  181. <style lang="scss">
  182. /*每个页面公共css */
  183. @import url("/components/gaoyia-parse/parse.css");
  184. @import '@/common/uni.css';
  185. page {
  186. height: 100%;
  187. }
  188. .display-flex-start {
  189. display: flex;
  190. align-items: center;
  191. }
  192. .display-flex-end {
  193. display: flex;
  194. justify-content: flex-end;
  195. align-items: center;
  196. }
  197. .display-between {
  198. display: flex;
  199. justify-content: space-between;
  200. }
  201. .display-around {
  202. display: flex;
  203. justify-content: space-around;
  204. }
  205. .display-between-column {
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: space-between;
  209. }
  210. .display-around-column {
  211. display: flex;
  212. flex-direction: column;
  213. justify-content: space-around;
  214. }
  215. .display-wrap {
  216. display: flex;
  217. flex-wrap: wrap;
  218. }
  219. .items-center {
  220. align-items: center;
  221. }
  222. // .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
  223. // max-height: 65%!important;
  224. // }
  225. </style>