App.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. getApp().globalData.isAuth = false;
  127. }
  128. else{
  129. getApp().globalData.isAuth = true;
  130. }
  131. uni.setStorageSync('openId', res.data.data.openid);
  132. // uni.hideLoading()
  133. }
  134. },
  135. fail: () => {
  136. console.log("连接失败");
  137. }
  138. });
  139. },
  140. getPhoneNumber(e){
  141. if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
  142. console.log(e.detail);
  143. getApp().phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key);
  144. return true;
  145. } else { //
  146. return false;
  147. }
  148. },
  149. phoneRequest(myIv,myEncryptedData,sKey){
  150. let url = getApp().makeApiUrl('user','user','phone');
  151. uni.request({
  152. url:url,
  153. method: 'POST',
  154. header: {
  155. 'content-type': 'application/x-www-form-urlencoded'
  156. },
  157. data: {
  158. iv:myIv,
  159. sessionKey:sKey,
  160. encryptedData:myEncryptedData,
  161. openId:getApp().globalData.open_id
  162. },
  163. success: (res) => {
  164. console.log(res)
  165. if(res.data.code === 200){
  166. getApp().globalData.user_phone = res.data.data;
  167. if (res.data.data != ""){
  168. getApp().globalData.isAuth = true;
  169. }
  170. }
  171. },
  172. fail: () => {
  173. console.log("连接失败");
  174. }
  175. });
  176. },
  177. }
  178. };
  179. </script>
  180. <style lang="scss">
  181. /*每个页面公共css */
  182. @import url("/components/gaoyia-parse/parse.css");
  183. @import '@/common/uni.css';
  184. page {
  185. height: 100%;
  186. }
  187. .display-flex-start {
  188. display: flex;
  189. align-items: center;
  190. }
  191. .display-flex-end {
  192. display: flex;
  193. justify-content: flex-end;
  194. align-items: center;
  195. }
  196. .display-between {
  197. display: flex;
  198. justify-content: space-between;
  199. }
  200. .display-around {
  201. display: flex;
  202. justify-content: space-around;
  203. }
  204. .display-between-column {
  205. display: flex;
  206. flex-direction: column;
  207. justify-content: space-between;
  208. }
  209. .display-around-column {
  210. display: flex;
  211. flex-direction: column;
  212. justify-content: space-around;
  213. }
  214. .display-wrap {
  215. display: flex;
  216. flex-wrap: wrap;
  217. }
  218. .items-center {
  219. align-items: center;
  220. }
  221. // .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
  222. // max-height: 65%!important;
  223. // }
  224. </style>