common.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. export default {
  2. shopName(){
  3. return "";
  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,param){
  28. var userInfo = uni.getStorageSync("user_data");
  29. var cacheShop = this.shopId();
  30. if(!userInfo){
  31. setTimeout(function(){
  32. uni.hideLoading();
  33. uni.$u.route({
  34. url:'/pages/user/login?store='+cacheShop,
  35. type:"navigateTo",
  36. animationType:"slide-in-bottom"
  37. });
  38. },800);
  39. return ;
  40. }
  41. if(type == 1 && !userInfo){
  42. uni.showToast({
  43. title:"请先登录",
  44. icon:"none"
  45. });
  46. return true;
  47. }
  48. uni.$u.route(url,param);
  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. // #ifdef APP-PLUS
  66. plus.nativeUI.toast(msg);
  67. // #endif
  68. // #ifdef MP
  69. uni.showToast({
  70. title: msg,
  71. icon: icon?icon:'none',
  72. mask: true,
  73. duration: 1500,
  74. success() {
  75. callback && (setTimeout(function() {
  76. callback();
  77. }, 1500));
  78. }
  79. });
  80. // #endif
  81. },
  82. /**
  83. * 操作错误提示
  84. * @param {*} msg
  85. * @param {*} showCancel
  86. * @param {*} callback
  87. * @param {*} title
  88. */
  89. showError(msg,callback,title = "友情提示",showCancel = true){
  90. uni.showModal({
  91. title: title,
  92. content: msg,
  93. showCancel: showCancel,
  94. success(res) {
  95. callback && callback(res);
  96. }
  97. });
  98. },
  99. showConfirm(msg,callback,title,yes,cancel){
  100. plus.nativeUI.confirm(msg, function(e){
  101. callback && callback(e);
  102. },
  103. {"title":title,"buttons":[yes?yes:"确定",cancel?cancel:"取消"]}
  104. );
  105. },
  106. showSysAlert(msg,callback,title,showCancel){
  107. plus.nativeUI.alert(msg,callback,title,showCancel);
  108. },
  109. showSysMsg(msg){
  110. plus.nativeUI.toast(msg);
  111. },
  112. /**
  113. * loading
  114. * @param {Object} msg
  115. * @param {Object} callback
  116. */
  117. loading(msg,callback){
  118. uni.showLoading({
  119. title:msg ?? '请求中...',
  120. mask:true,
  121. success(res) {
  122. callback && callback(res);
  123. }
  124. })
  125. },
  126. hideLoad(){
  127. uni.hideLoading();
  128. },
  129. formatDate(value) {
  130. const data = new Date(value);
  131. const month = data.getMonth() + 1;
  132. const day = data.getDate();
  133. const year = data.getFullYear();
  134. const hours = data.getHours();
  135. const minutes = data.getMinutes();
  136. const seconds = data.getSeconds();
  137. const formattedTime = `${year}-${month}-${day}`;
  138. // const formattedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  139. return formattedTime;
  140. },
  141. formatMoney(num) {
  142. if (num == 0) return "¥0.00";
  143. return Intl.NumberFormat("zh-CN", {
  144. style: "currency",
  145. currency: "CNY",
  146. minimumFractionDigits: 2,
  147. maximumFractionDigits: 2,
  148. }).format(num / 100);
  149. }
  150. }