common.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import $store from '../store'
  2. import request from '@/utils/request.js'
  3. const isUserId = function() {
  4. var userId=uni.getStorageSync("wxOpenData").loginInfo.uid;
  5. //console.log("userId---"+userId)
  6. if(!userId){
  7. uni.navigateTo({
  8. url:'../login/login'
  9. })
  10. }
  11. }
  12. const automaticlogin = function() {
  13. //console.log($store.state.userInfo)
  14. var that=this;
  15. const extConfig = uni.getExtConfigSync();
  16. //console.log(extConfig)
  17. return new Promise((resolve, reject) => {
  18. if($store.state.userInfo){
  19. resolve()
  20. }else{
  21. uni.login({
  22. provider: 'weixin',
  23. success: function (loginRes) {
  24. //console.log(loginRes);
  25. request.http('miniApp2/sys/getWxOpenID', {
  26. code:loginRes.code,
  27. unionId:extConfig.unionId
  28. },'GET').then(res => {
  29. $store.commit('mutationswxOpenData', res.data);
  30. var themeColor= res.data.themeColor
  31. uni.setStorageSync('themeColor',themeColor);
  32. if(res.data.loginInfo){
  33. $store.commit('mutationsuserInfo', res.data.loginInfo.openUser)
  34. }
  35. resolve()
  36. })
  37. }
  38. });
  39. }
  40. })
  41. //return Promise.resolve()
  42. }
  43. /* const uid =function() {
  44. var userId=uni.getStorageSync("logodata").uid;
  45. return
  46. } */
  47. // 防止处理多次点击
  48. function noMultipleClicks(methods, info) {
  49. // methods是点击后需要执行的函数, info是函数需要传的参数
  50. let that = this;
  51. if (that.noClick) {
  52. // 第一次点击
  53. that.noClick= false;
  54. if((info && info !== '') || info ==0) {
  55. // info是执行函数需要传的参数
  56. methods(info);
  57. } else {
  58. methods();
  59. }
  60. setTimeout(()=> {
  61. that.noClick= true;
  62. }, 3000)
  63. } else {
  64. // 这里是重复点击的判断
  65. }
  66. }
  67. function getExtStoreId(type){
  68. try{
  69. var extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'};
  70. /* extConfig={
  71. "shopId": "1F12DB68-D8E8-4B76-9E20-287ACB72889F",
  72. "url":"https://apidms.66km.com",
  73. "unionId":"EF7981B9-2D1D-4006-9C0A-66CE7177134D",
  74. "appId":"wx2c6f04c0dcd15984"
  75. } */
  76. console.log(extConfig,'extJson对象');
  77. //return extConfig[type];
  78. return extConfig
  79. }catch(err){
  80. console.log(err,'getExtStoreId__error')
  81. }
  82. }
  83. function formateTimeStamp (timeStamp) {
  84. var hour;
  85. var min;
  86. var seconds;
  87. let today = new Date() // 当前时间
  88. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  89. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  90. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  91. //console.log(shengyuD+'shengyuD')
  92. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  93. hour = parseInt(shenyu / (60 * 60 * 1000))
  94. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  95. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  96. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  97. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  98. if (hour < 10) {
  99. hour = '0' + hour
  100. }
  101. //console.log(hour)
  102. if (min < 10) {
  103. min = '0' + min;
  104. }
  105. //console.log(min)
  106. if (seconds < 10) {
  107. seconds = '0' + seconds;
  108. }
  109. //console.log(seconds)
  110. const restTime = {
  111. hour: hour,
  112. min: min,
  113. seconds: seconds
  114. }
  115. //console.log(restTime)
  116. /// setTimeout(formateTimeStamp(timeStamp), 1000)
  117. return restTime
  118. }
  119. function countdown (timeStamp) {
  120. var hour;
  121. var min;
  122. var seconds;
  123. let today = new Date() // 当前时间
  124. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  125. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  126. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  127. //console.log(shengyuD+'shengyuD')
  128. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  129. hour = parseInt(shenyu / (60 * 60 * 1000))
  130. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  131. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  132. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  133. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  134. if (hour < 10) {
  135. hour = '0' + hour
  136. }
  137. console.log(hour)
  138. if (min < 10) {
  139. min = '0' + min;
  140. }
  141. //console.log(min)
  142. if (seconds < 10) {
  143. seconds = '0' + seconds;
  144. }
  145. const restTime = {
  146. hour: hour,
  147. min: min,
  148. seconds: seconds
  149. }
  150. var txt = hour+':'+min+':'+seconds;
  151. console.log(txt)
  152. return txt
  153. }
  154. export default {
  155. commonData:{
  156. companyType:1,
  157. },
  158. automaticlogin,
  159. isUserId,
  160. getExtStoreId,
  161. noMultipleClicks, // 禁止多次点击
  162. formateTimeStamp,
  163. countdown
  164. }