globalMixin.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { boot } from "quasar/wrappers";
  2. import vueCountryRegionSelect from "vue3-country-region-select";
  3. // "async" is optional;
  4. // more info on params: https://v2.quasar.dev/quasar-cli/boot-files
  5. export default boot(async (/* { app, router, ... } */ { app, router }) => {
  6. // something to do
  7. const testGlobal2 = () => {
  8. console.log("testGlobal2");
  9. };
  10. app.use(vueCountryRegionSelect);
  11. const normalizeMultiImageUrl = (input) => {
  12. if (input.indexOf(",") > -1) {
  13. return input.split(",").shift();
  14. } else if (input.indexOf(";") > -1) {
  15. return input.split(";").shift();
  16. }
  17. return input;
  18. };
  19. const removeHtmlTag = (input) => {
  20. var div = document.createElement("div");
  21. div.innerHTML = input;
  22. var text = div.textContent || div.innerText || "";
  23. return text;
  24. };
  25. const generalNotify = (q, isPositive, message) => {
  26. q.notify({
  27. position: "top-right",
  28. timeout: 2500,
  29. color: isPositive ? "positive" : "negative",
  30. textColor: "white",
  31. message: message,
  32. actions: [{ icon: "close", color: "white" }],
  33. });
  34. };
  35. const goPage = (val) => {
  36. router.push(val);
  37. };
  38. const checkEmpty = (val) => {
  39. if (val == null || val.length < 1) {
  40. return true;
  41. } else {
  42. return false;
  43. }
  44. };
  45. const showLoading = (q) => {
  46. q.loading.show();
  47. };
  48. const hideLoading = (q) => {
  49. q.loading.hide();
  50. };
  51. app.config.globalProperties.$testGlobal2 = testGlobal2;
  52. app.config.globalProperties.$normalizeMultiImageUrl = normalizeMultiImageUrl;
  53. app.config.globalProperties.$removeHtmlTag = removeHtmlTag;
  54. app.config.globalProperties.$generalNotify = generalNotify;
  55. app.config.globalProperties.$goPage = goPage;
  56. app.config.globalProperties.$checkEmpty = checkEmpty;
  57. app.config.globalProperties.$showLoading = showLoading;
  58. app.config.globalProperties.$hideLoading = hideLoading;
  59. app.mixin({
  60. methods: {
  61. testGlobal2,
  62. generalNotify,
  63. normalizeMultiImageUrl,
  64. removeHtmlTag,
  65. gotoUrl(url) {
  66. window.location = url;
  67. },
  68. goPage,
  69. checkEmpty,
  70. showLoading,
  71. hideLoading,
  72. },
  73. });
  74. });