mixins.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import Vue from 'vue'
  2. import i18n from './langs/i18n'
  3. Vue.mixin({
  4. data: function () {
  5. return {
  6. appVersion: window.appVersion
  7. }
  8. },
  9. methods: {
  10. async appLogout(evt) {
  11. if (this.$root.appConfig.proxyAuth) {
  12. if (this.$root.appConfig.proxyLogoutUrl) {
  13. location.assign(this.$root.appConfig.proxyLogoutUrl)
  14. }
  15. else return false
  16. }
  17. else {
  18. await this.axios.get('/user/logout')
  19. this.$storage.clear()
  20. this.$router.push({ name: 'login', params: { forceRefresh: true } })
  21. }
  22. },
  23. exitSettings: function (event) {
  24. if (event) {
  25. this.$notify({ clean: true })
  26. this.$router.push({ name: 'accounts' })
  27. }
  28. },
  29. isUrl: function (url) {
  30. var strRegex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/
  31. var re = new RegExp(strRegex)
  32. return re.test(url)
  33. },
  34. openInBrowser(uri) {
  35. const a = document.createElement('a')
  36. a.setAttribute('href', uri)
  37. a.dispatchEvent(new MouseEvent("click", { 'view': window, 'bubbles': true, 'cancelable': true }))
  38. },
  39. /**
  40. *
  41. */
  42. inputId(fieldType, fieldName) {
  43. let prefix
  44. fieldName = fieldName.toString()
  45. switch (fieldType) {
  46. case 'button':
  47. prefix = 'txt'
  48. break
  49. case 'button':
  50. prefix = 'btn'
  51. break
  52. case 'email':
  53. prefix = 'eml'
  54. break
  55. case 'password':
  56. prefix = 'pwd'
  57. break
  58. case 'radio':
  59. prefix = 'rdo'
  60. break
  61. case 'label':
  62. prefix = 'lbl'
  63. break
  64. default:
  65. prefix = 'txt'
  66. break
  67. }
  68. return prefix + fieldName[0].toUpperCase() + fieldName.toLowerCase().slice(1);
  69. // button
  70. // checkbox
  71. // color
  72. // date
  73. // datetime-local
  74. // file
  75. // hidden
  76. // image
  77. // month
  78. // number
  79. // radio
  80. // range
  81. // reset
  82. // search
  83. // submit
  84. // tel
  85. // text
  86. // time
  87. // url
  88. // week
  89. },
  90. setTheme(theme) {
  91. document.documentElement.dataset.theme = theme;
  92. },
  93. applyPreferences(preferences) {
  94. for (const preference in preferences) {
  95. try {
  96. this.$root.userPreferences[preference] = preferences[preference]
  97. }
  98. catch (e) {
  99. console.log(e)
  100. }
  101. }
  102. if (this.$root.userPreferences.lang != 'browser') {
  103. i18n.locale = this.$root.userPreferences.lang
  104. document.documentElement.lang = this.$root.userPreferences.lang
  105. }
  106. },
  107. }
  108. })