App.vue 5.7 KB

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