common.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. export default {
  2. shopId: function() {
  3. return "10108575743725";
  4. },
  5. clearUri(url){
  6. var userInfo = uni.getStorageSync("user_data");
  7. if(!userInfo){
  8. uni.showLoading({
  9. title:"加载中..."
  10. });
  11. setTimeout(function(){
  12. uni.hideLoading();
  13. uni.$u.route({
  14. url:'/pages/user/user',
  15. type:"switchTab",
  16. animationType:"slide-in-bottom"
  17. });
  18. },800);
  19. return ;
  20. }
  21. uni.$u.route({
  22. url:url,
  23. animationType:"slide-in-bottom",
  24. animationDuration:300
  25. });
  26. },
  27. jumpUri(url,type){
  28. var userInfo = uni.getStorageSync("user_token");
  29. if(!userInfo){
  30. setTimeout(function(){
  31. uni.hideLoading();
  32. uni.navigateTo({
  33. url:'/pages/auth/login',
  34. animationType:"slide-in-bottom"
  35. });
  36. },800);
  37. return false;
  38. }
  39. if(type == 1 && !userInfo){
  40. uni.showToast({
  41. title:"请先登录",
  42. icon:"none"
  43. });
  44. return true;
  45. }
  46. uni.navigateTo({
  47. url:url
  48. })
  49. },
  50. //判断是否登录
  51. navTo: function(url,param) {
  52. uni.$u.route(url,param);
  53. },
  54. //判断是否登录
  55. isLogin: function() {
  56. return uni.getStorageSync("user") ? true : false
  57. },
  58. /**
  59. * 操作成功提示框
  60. * @param {*} msg
  61. * @param {*} callback
  62. * @param {*} icon
  63. */
  64. showSuccess(msg,icon,callback){
  65. uni.showToast({
  66. title: msg,
  67. icon: icon?icon:'none',
  68. mask: true,
  69. duration: 1500,
  70. success() {
  71. callback && (setTimeout(function() {
  72. callback();
  73. }, 1500));
  74. }
  75. });
  76. },
  77. /**
  78. * 操作错误提示
  79. * @param {*} msg
  80. * @param {*} showCancel
  81. * @param {*} callback
  82. * @param {*} title
  83. */
  84. showError(msg,callback,title = "友情提示",showCancel = true){
  85. uni.showModal({
  86. title: title,
  87. content: msg,
  88. showCancel: showCancel,
  89. success(res) {
  90. callback && callback(res);
  91. }
  92. });
  93. },
  94. showConfirm(msg,callback,title,yes,cancel){
  95. plus.nativeUI.confirm(msg, function(e){
  96. callback && callback(e);
  97. },
  98. {"title":title,"buttons":[yes?yes:"确定",cancel?cancel:"取消"]}
  99. );
  100. },
  101. showSysAlert(msg,callback,title,showCancel){
  102. plus.nativeUI.alert(msg,callback,title,showCancel);
  103. },
  104. showSysMsg(msg){
  105. plus.nativeUI.toast(msg);
  106. },
  107. /**
  108. * loading
  109. * @param {Object} msg
  110. * @param {Object} callback
  111. */
  112. loading(msg,callback){
  113. uni.showLoading({
  114. title:msg ?? '请求中...',
  115. mask:true,
  116. success(res) {
  117. callback && callback(res);
  118. }
  119. })
  120. },
  121. hideLoad(){
  122. uni.hideLoading();
  123. },
  124. formatDate(value) {
  125. const data = new Date(value);
  126. const month = data.getMonth() + 1;
  127. const day = data.getDate();
  128. const year = data.getFullYear();
  129. const hours = data.getHours();
  130. const minutes = data.getMinutes();
  131. const seconds = data.getSeconds();
  132. const formattedTime = `${year}-${month}-${day}`;
  133. // const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  134. return formattedTime;
  135. },
  136. formatMoney(num,double = false) {
  137. if (num == 0) return "¥0.00";
  138. if (!double) {
  139. return "¥"+num.toFixed(2);
  140. }
  141. return "¥"+(num / 100).toFixed(2);
  142. // return Intl.NumberFormat("zh-CN", {
  143. // style: "currency",
  144. // currency: "CNY",
  145. // minimumFractionDigits: 2,
  146. // maximumFractionDigits: 2,
  147. // }).format(num / 100);
  148. },
  149. disFormat(num,num2) {
  150. if (!num) return "0";
  151. if (!num2) return "0";
  152. var total = ((num*100)/(num2*100)*10)
  153. return total.toFixed(1)
  154. },
  155. dateFormat(date, fmt='yyyy-MM-dd hh:mm:ss') {
  156. date = new Date(date)
  157. var o = {
  158. "M+" : date.getMonth()+1, //月份
  159. "d+" : date.getDate(), //日
  160. "h+" : date.getHours(), //小时
  161. "m+" : date.getMinutes(), //分
  162. "s+" : date.getSeconds(), //秒
  163. "q+" : Math.floor((date.getMonth()+3)/3), //季度
  164. "S" : date.getMilliseconds() //毫秒
  165. };
  166. if(/(y+)/.test(fmt)) {
  167. fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
  168. }
  169. for(var k in o) {
  170. if(new RegExp("("+ k +")").test(fmt)){
  171. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  172. }
  173. }
  174. return fmt;
  175. }
  176. }