| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <script>
- import md5 from '@/common/md5.js';
- export default {
- globalData: {
- //shareUrl: "https://heater.xazhima.com/", 测试地址
- shareUrl:"https://h.xayuanju.com/",
- globalTimestamp: Date.now().toString(),
- secret: "Heater_weichat_app_zhima",
- selectedIndex:0,
- isSider:false,
- user_id: '',
- open_id:'',
- //open_id:"oX46e5ImwFndnH442HW6Yt7W9Mck",//测试使用 替换正确appId后默认为空
- user_status:'',
- user_name:'',
- user_phone:'',
- user_headUrl:'',
- globalAuth:false,
- isAuth : false,
- session_key: '',
- contact_name:'',
- company_name:'',
- company_logo:'',
- isAndroid:false,
- nowTime:'',
- statusObj:{
- '0':'未缴费',
- '1':'已缴费',
- '2':'空置已缴费',
- '3':'空置转全额'
- },
- statusColor:{
- '0':'#D9001B',
- '1':'#70B603',
- '2':'#4B7902',
- '3':'#BFBF00',
- }
- },
- onLaunch: function () {
- console.log("App Launch");
- // let equType = uni.getSystemInfoSync().platform;
- // switch(equType){
- // case 'android':
- // console.log('运行Android上')
- // setTimeout(()=>{
- // getApp().globalData.isAndroid = true
- // },100)
- // break;
- // case 'ios':
- // console.log('运行iOS上');
- // break;
- // default:
- // console.log('运行在开发者工具上')
- // break;
- // }
- this.loginLoad();
- },
- onShow: function () {
- console.log("App Show");
- uni.hideTabBar({})
- },
- onHide: function () {
- console.log("App Hide");
- },
- methods:{
- getNowTime(){
- let time = new Date(Date.now());
- const y = time.getFullYear();
- const m =
- time.getMonth() + 1 < 10
- ? "0" + (time.getMonth() + 1)
- : time.getMonth() + 1;
- const d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
- // const h = time.getHours()
- // const mm = time.getMinutes();
- // const s = time.getSeconds();
- return y + "-" + m + "-" + d;
- },
- loginLoad(){
- let that = this;
- uni.login({
- success(res) {
- that.loginRequest(res.code)
- }
- })
- },
- makeApiUrl(method,source,action){
- let timestamp = Date.now().toString();
- let md5Sign = md5("method="+method+"×tamp="+timestamp+"&secret="+getApp().globalData.secret);
- let url = getApp().globalData.shareUrl+'api/api.php'+'?method='+method+'&source='+source+'&action='+action+'×tamp='+timestamp +'&sign='+md5Sign;
- return url;
- },
- MD5(str){
- let md5str = md5(str);
- return md5str.toUpperCase();
- },
- randomStr(len){
- let str = '';
- let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- for (let i = 0; i < len; i++){
- str += chars.charAt(Math.random() * chars.length);
- }
- return str;
- },
-
- loginRequest(codeRes){
- let url = getApp().makeApiUrl("user",'user','login');
- uni.request({
- url:url,
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: {
- code:codeRes
- },
-
- success: (res) => {
- console.log(res)
- if(res.data.code === 200){
- getApp().globalData.session_key = res.data.data.session_key;
- getApp().globalData.open_id = res.data.data.openid;
- getApp().globalData.user_status = res.data.data.status;
- getApp().globalData.user_phone = res.data.data.phone;
- getApp().globalData.nowTime = this.getNowTime();
- if (res.data.data.phone === ''){
- //必须有手机号才算登录成功,系统才可用。
- // console.log("res.data.data.phone="+res.data.data.phone);
- getApp().globalData.isAuth = false;
- }
- else{
- getApp().globalData.isAuth = true;
- }
- uni.setStorageSync('openId', res.data.data.openid);
- // uni.hideLoading()
- }
- },
- fail: () => {
- console.log("连接失败");
- }
- });
- },
- getPhoneNumber(e){
- if (e.detail.errMsg == 'getPhoneNumber:ok') { //允许授权执行跳转
- console.log(e.detail);
- getApp().phoneRequest(e.detail.iv, e.detail.encryptedData, getApp().globalData.session_key);
- return true;
- } else { //
- return false;
- }
- },
- phoneRequest(myIv,myEncryptedData,sKey){
- let url = getApp().makeApiUrl('user','user','phone');
- uni.request({
- url:url,
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data: {
- iv:myIv,
- sessionKey:sKey,
- encryptedData:myEncryptedData,
- openId:getApp().globalData.open_id
- },
- success: (res) => {
- console.log(res)
- if(res.data.code === 200){
- getApp().globalData.user_phone = res.data.data;
- if (res.data.data != ""){
- getApp().globalData.isAuth = true;
- }
- }
- },
- fail: () => {
- console.log("连接失败");
- }
- });
- },
- }
- };
- </script>
- <style lang="scss">
- /*每个页面公共css */
- @import url("/components/gaoyia-parse/parse.css");
- @import '@/common/uni.css';
- page {
- height: 100%;
- }
- .display-flex-start {
- display: flex;
- align-items: center;
- }
- .display-flex-end {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- }
- .display-between {
- display: flex;
- justify-content: space-between;
- }
- .display-around {
- display: flex;
- justify-content: space-around;
- }
- .display-between-column {
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .display-around-column {
- display: flex;
- flex-direction: column;
- justify-content: space-around;
- }
- .display-wrap {
- display: flex;
- flex-wrap: wrap;
- }
- .items-center {
- align-items: center;
- }
- // .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
- // max-height: 65%!important;
- // }
- </style>
|