综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * 显示消息提示框
  3. * @param content 提示的标题
  4. */
  5. export function toast(content) {
  6. uni.showToast({
  7. icon: 'none',
  8. title: content
  9. })
  10. }
  11. /**
  12. * 显示模态弹窗
  13. * @param content 提示的标题
  14. */
  15. export function showConfirm(content) {
  16. return new Promise((resolve, reject) => {
  17. uni.showModal({
  18. title: '提示',
  19. content: content,
  20. cancelText: '取消',
  21. confirmText: '确定',
  22. success: function (res) {
  23. resolve(res)
  24. }
  25. })
  26. })
  27. }
  28. /**
  29. * 参数处理
  30. * @param params 参数
  31. */
  32. export function tansParams(params) {
  33. let result = ''
  34. for (const propName of Object.keys(params)) {
  35. const value = params[propName]
  36. var part = encodeURIComponent(propName) + "="
  37. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  38. if (typeof value === 'object') {
  39. for (const key of Object.keys(value)) {
  40. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  41. let params = propName + '[' + key + ']'
  42. var subPart = encodeURIComponent(params) + "="
  43. result += subPart + encodeURIComponent(value[key]) + "&"
  44. }
  45. }
  46. } else {
  47. result += part + encodeURIComponent(value) + "&"
  48. }
  49. }
  50. }
  51. return result
  52. }
  53. // 转换字符串,undefined,null等转化为""
  54. export function parseStrEmpty(str) {
  55. if (!str || str == "undefined" || str == "null") {
  56. return "";
  57. }
  58. return str;
  59. }
  60. export function parseTime(time, pattern) {
  61. if (arguments.length === 0 || !time) {
  62. return null
  63. }
  64. const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
  65. let date
  66. if (typeof time === 'object') {
  67. date = time
  68. } else {
  69. if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
  70. time = parseInt(time)
  71. } else if (typeof time === 'string') {
  72. time = time.replace(new RegExp(/-/gm), '/').replace('T', ' ').replace(new RegExp(/\.[\d]{3}/gm), '');
  73. }
  74. if ((typeof time === 'number') && (time.toString().length === 10)) {
  75. time = time * 1000
  76. }
  77. date = new Date(time)
  78. }
  79. const formatObj = {
  80. y: date.getFullYear(),
  81. m: date.getMonth() + 1,
  82. d: date.getDate(),
  83. h: date.getHours(),
  84. i: date.getMinutes(),
  85. s: date.getSeconds(),
  86. a: date.getDay()
  87. }
  88. const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
  89. let value = formatObj[key]
  90. // Note: getDay() returns 0 on Sunday
  91. if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
  92. if (result.length > 0 && value < 10) {
  93. value = '0' + value
  94. }
  95. return value || 0
  96. })
  97. return time_str
  98. }
  99. export function getFileName(name) {
  100. if (name) {
  101. let arr = name.split("/");
  102. return arr[arr.length - 1];
  103. }
  104. }