common.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. var extConfig = uni.getExtConfigSync();
  16. /* extConfig={
  17. "shopId": "23173848-292E-4AEA-B590-73AC9A763F1D",
  18. "url":"https://store-api.qdbtl.cn/",
  19. "unionId":"C3748B46-B778-40AA-8C60-A9B0F2FA23A7",
  20. "appId":"wxc023ff04deb28f2d"
  21. } */
  22. console.log("automaticlogin")
  23. console.log(extConfig)
  24. return new Promise((resolve, reject) => {
  25. if($store.state.userInfo){
  26. resolve()
  27. }else{
  28. uni.login({
  29. provider: 'weixin',
  30. success: function (loginRes) {
  31. //console.log(loginRes);
  32. uni.showLoading({
  33. title: '加载中'
  34. });
  35. request.http('miniApp2/sys/getWxOpenID', {
  36. code:loginRes.code,
  37. unionId:extConfig.unionId
  38. },'GET').then(res => {
  39. uni.hideLoading();
  40. $store.commit('mutationswxOpenData', res.data);
  41. var themeColor= res.data.themeColor
  42. uni.setStorageSync('themeColor',themeColor);
  43. if(res.data.loginInfo){
  44. $store.commit('mutationsuserInfo', res.data.loginInfo.openUser)
  45. }
  46. resolve()
  47. })
  48. }
  49. });
  50. }
  51. })
  52. //return Promise.resolve()
  53. }
  54. /* const uid =function() {
  55. var userId=uni.getStorageSync("logodata").uid;
  56. return
  57. } */
  58. // 防止处理多次点击
  59. function noMultipleClicks(methods, info) {
  60. // methods是点击后需要执行的函数, info是函数需要传的参数
  61. let that = this;
  62. if (that.noClick) {
  63. // 第一次点击
  64. that.noClick= false;
  65. if((info && info !== '') || info ==0) {
  66. // info是执行函数需要传的参数
  67. methods(info);
  68. } else {
  69. methods();
  70. }
  71. setTimeout(()=> {
  72. that.noClick= true;
  73. }, 3000)
  74. } else {
  75. // 这里是重复点击的判断
  76. }
  77. }
  78. function getExtStoreId(type){
  79. try{
  80. var extConfig = uni.getExtConfigSync ? uni.getExtConfigSync() : {shopId:'默认的门店id'};
  81. /* extConfig={
  82. "shopId": "E37BB296-5A08-4534-859D-B351BA611AF9",
  83. "url":"https://apidms.66km.com",
  84. "unionId":"EF7981B9-2D1D-4006-9C0A-66CE7177134D",
  85. "appId":"wx2c6f04c0dcd15984"
  86. } */
  87. /* extConfig={
  88. "shopId": "23173848-292E-4AEA-B590-73AC9A763F1D",
  89. "url":"https://store-api.qdbtl.cn/",
  90. "unionId":"C3748B46-B778-40AA-8C60-A9B0F2FA23A7",
  91. "appId":"wxc023ff04deb28f2d"
  92. } */
  93. /* extConfig={
  94. "shopId": "4490D0C9-176B-4C34-BE50-111CA3FA4DC1",
  95. "url":"https://apidms.jcatt.cn/",
  96. "unionId":"9DE2D6D6-D59A-401B-8275-F5DACC99AC22",
  97. "appId":"wx575a8b1339951f27"
  98. } */
  99. /* extConfig={
  100. "shopId": "4490D0C9-176B-4C34-BE50-111CA3FA4DC1",
  101. "url":"https://apidms.dqcarlink.com/",
  102. "unionId":"AE2F2070-2D29-4BDD-978E-0CF419763FCE",
  103. "appId":"wx08744a0003d06f3c"
  104. } */
  105. console.log(extConfig,'extJson对象');
  106. //return extConfig[type];
  107. return extConfig
  108. }catch(err){
  109. console.log(err,'getExtStoreId__error')
  110. }
  111. }
  112. function formateTimeStamp (timeStamp) {
  113. var hour;
  114. var min;
  115. var seconds;
  116. let today = new Date() // 当前时间
  117. if (Number(new Date(timeStamp).getTime()) < Number(new Date().getTime())) {
  118. const zTime = {
  119. hour: 0,
  120. min: 0,
  121. seconds: 0
  122. }
  123. return zTime
  124. return false
  125. }
  126. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  127. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  128. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  129. //console.log(shengyuD+'shengyuD')
  130. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  131. hour = parseInt(shenyu / (60 * 60 * 1000))
  132. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  133. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  134. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  135. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  136. if (hour < 10) {
  137. hour = '0' + hour
  138. }
  139. //console.log(hour)
  140. if (min < 10) {
  141. min = '0' + min;
  142. }
  143. //console.log(min)
  144. if (seconds < 10) {
  145. seconds = '0' + seconds;
  146. }
  147. //console.log(seconds)
  148. const restTime = {
  149. hour: hour,
  150. min: min,
  151. seconds: seconds
  152. }
  153. //console.log(restTime)
  154. /// setTimeout(formateTimeStamp(timeStamp), 1000)
  155. return restTime
  156. }
  157. function countdown (timeStamp) {
  158. var hour;
  159. var min;
  160. var seconds;
  161. let today = new Date() // 当前时间
  162. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  163. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  164. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  165. //console.log(shengyuD+'shengyuD')
  166. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  167. hour = parseInt(shenyu / (60 * 60 * 1000))
  168. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  169. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  170. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  171. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  172. if (hour < 10) {
  173. hour = '0' + hour
  174. }
  175. console.log(hour)
  176. if (min < 10) {
  177. min = '0' + min;
  178. }
  179. //console.log(min)
  180. if (seconds < 10) {
  181. seconds = '0' + seconds;
  182. }
  183. const restTime = {
  184. hour: hour,
  185. min: min,
  186. seconds: seconds
  187. }
  188. var txt = hour+':'+min+':'+seconds;
  189. console.log(txt)
  190. return txt
  191. }
  192. export default {
  193. commonData:{
  194. companyType:1,
  195. },
  196. automaticlogin,
  197. isUserId,
  198. getExtStoreId,
  199. noMultipleClicks, // 禁止多次点击
  200. formateTimeStamp,
  201. countdown
  202. }