common.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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": "23173848-292E-4AEA-B590-73AC9A763F1D",
  83. "url":"https://store-api.qdbtl.cn/",
  84. "unionId":"C3748B46-B778-40AA-8C60-A9B0F2FA23A7",
  85. "appId":"wxc023ff04deb28f2d"
  86. } */
  87. /*
  88. "shopId": "E37BB296-5A08-4534-859D-B351BA611AF9",
  89. "url":"http://api.dms.66km.com.cn",
  90. "unionId":"EEADACCD-8A19-499D-8AD7-6975D2C93243",
  91. "appId":"wx33053a645546ec31"
  92. */
  93. console.log(extConfig,'extJson对象');
  94. //return extConfig[type];
  95. return extConfig
  96. }catch(err){
  97. console.log(err,'getExtStoreId__error')
  98. }
  99. }
  100. function formateTimeStamp (timeStamp) {
  101. var hour;
  102. var min;
  103. var seconds;
  104. let today = new Date() // 当前时间
  105. if (Number(new Date(timeStamp).getTime()) < Number(new Date().getTime())) {
  106. const zTime = {
  107. hour: 0,
  108. min: 0,
  109. seconds: 0
  110. }
  111. return zTime
  112. return false
  113. }
  114. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  115. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  116. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  117. //console.log(shengyuD+'shengyuD')
  118. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  119. hour = parseInt(shenyu / (60 * 60 * 1000))
  120. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  121. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  122. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  123. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  124. if (hour < 10) {
  125. hour = '0' + hour
  126. }
  127. //console.log(hour)
  128. if (min < 10) {
  129. min = '0' + min;
  130. }
  131. //console.log(min)
  132. if (seconds < 10) {
  133. seconds = '0' + seconds;
  134. }
  135. //console.log(seconds)
  136. const restTime = {
  137. hour: hour,
  138. min: min,
  139. seconds: seconds
  140. }
  141. //console.log(restTime)
  142. /// setTimeout(formateTimeStamp(timeStamp), 1000)
  143. return restTime
  144. }
  145. function countdown (timeStamp) {
  146. var hour;
  147. var min;
  148. var seconds;
  149. let today = new Date() // 当前时间
  150. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  151. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  152. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  153. //console.log(shengyuD+'shengyuD')
  154. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  155. hour = parseInt(shenyu / (60 * 60 * 1000))
  156. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  157. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  158. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  159. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  160. if (hour < 10) {
  161. hour = '0' + hour
  162. }
  163. console.log(hour)
  164. if (min < 10) {
  165. min = '0' + min;
  166. }
  167. //console.log(min)
  168. if (seconds < 10) {
  169. seconds = '0' + seconds;
  170. }
  171. const restTime = {
  172. hour: hour,
  173. min: min,
  174. seconds: seconds
  175. }
  176. var txt = hour+':'+min+':'+seconds;
  177. console.log(txt)
  178. return txt
  179. }
  180. export default {
  181. commonData:{
  182. companyType:1,
  183. },
  184. automaticlogin,
  185. isUserId,
  186. getExtStoreId,
  187. noMultipleClicks, // 禁止多次点击
  188. formateTimeStamp,
  189. countdown
  190. }