common.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. console.log(extConfig,'extJson对象');
  100. //return extConfig[type];
  101. return extConfig
  102. }catch(err){
  103. console.log(err,'getExtStoreId__error')
  104. }
  105. }
  106. function formateTimeStamp (timeStamp) {
  107. var hour;
  108. var min;
  109. var seconds;
  110. let today = new Date() // 当前时间
  111. if (Number(new Date(timeStamp).getTime()) < Number(new Date().getTime())) {
  112. const zTime = {
  113. hour: 0,
  114. min: 0,
  115. seconds: 0
  116. }
  117. return zTime
  118. return false
  119. }
  120. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  121. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  122. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  123. //console.log(shengyuD+'shengyuD')
  124. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  125. hour = parseInt(shenyu / (60 * 60 * 1000))
  126. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  127. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  128. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  129. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  130. if (hour < 10) {
  131. hour = '0' + hour
  132. }
  133. //console.log(hour)
  134. if (min < 10) {
  135. min = '0' + min;
  136. }
  137. //console.log(min)
  138. if (seconds < 10) {
  139. seconds = '0' + seconds;
  140. }
  141. //console.log(seconds)
  142. const restTime = {
  143. hour: hour,
  144. min: min,
  145. seconds: seconds
  146. }
  147. //console.log(restTime)
  148. /// setTimeout(formateTimeStamp(timeStamp), 1000)
  149. return restTime
  150. }
  151. function countdown (timeStamp) {
  152. var hour;
  153. var min;
  154. var seconds;
  155. let today = new Date() // 当前时间
  156. let startTime = new Date(timeStamp.replace(/-/g, '/')) // 结束时间
  157. let shenyu = startTime.getTime() - today.getTime() // 倒计时毫秒数
  158. let shengyuD = parseInt(shenyu / (60 * 60 * 24 * 1000)) // 转换为天
  159. //console.log(shengyuD+'shengyuD')
  160. //hour = parseInt(shenyu / (60 * 60)) // 计算整数小时数
  161. hour = parseInt(shenyu / (60 * 60 * 1000))
  162. var afterHour = shenyu - hour * 60 * 60 * 1000 // 取得算出小时数后剩余的秒数
  163. min = parseInt(afterHour / (60 * 1000)) // 计算整数分
  164. //seconds = parseInt(shenyu - hour * 60 * 60 - min * 60) // 取得算出分后剩余的秒数
  165. seconds= parseInt((shenyu - shengyuD * 60 * 60 * 24 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000) / 1000)
  166. if (hour < 10) {
  167. hour = '0' + hour
  168. }
  169. console.log(hour)
  170. if (min < 10) {
  171. min = '0' + min;
  172. }
  173. //console.log(min)
  174. if (seconds < 10) {
  175. seconds = '0' + seconds;
  176. }
  177. const restTime = {
  178. hour: hour,
  179. min: min,
  180. seconds: seconds
  181. }
  182. var txt = hour+':'+min+':'+seconds;
  183. console.log(txt)
  184. return txt
  185. }
  186. export default {
  187. commonData:{
  188. companyType:1,
  189. },
  190. automaticlogin,
  191. isUserId,
  192. getExtStoreId,
  193. noMultipleClicks, // 禁止多次点击
  194. formateTimeStamp,
  195. countdown
  196. }