tools.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //确认框
  2. export const showModal = async ({title, content, confirmText, cancelText}) => {
  3. return new Promise((resolve) => {
  4. uni.showModal({
  5. title: title,
  6. content: content,
  7. confirmText: confirmText ?? '确定',
  8. cancelText: cancelText ?? '取消',
  9. success: function (res) {
  10. if (res.confirm) {
  11. resolve(true)
  12. } else if (res.cancel) {
  13. resolve(false)
  14. }
  15. }
  16. });
  17. })
  18. }
  19. //成功提示
  20. export const successToast = (title = '成功', duration= 2000) => {
  21. uni.showToast({
  22. title: title,
  23. duration: duration,
  24. mask: true
  25. });
  26. }
  27. //失败提示
  28. export const errorToast = (title = '失败', duration= 1500) => {
  29. uni.showToast({
  30. title: title,
  31. duration: duration,
  32. icon: 'none'
  33. });
  34. }
  35. //表单验证
  36. export const formValidate = async (formRef) => {
  37. return new Promise( (resolve) => {
  38. formRef.validate().then((res) => {
  39. resolve(true)
  40. }).catch(err => {
  41. resolve(false)
  42. })
  43. });
  44. }