refactor code

This commit is contained in:
Kittapath 2023-05-16 22:23:32 +07:00
parent d2c352de17
commit 92fc21033d
50 changed files with 652 additions and 2170 deletions

19
src/stores/data.ts Normal file
View file

@ -0,0 +1,19 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useDataStore = defineStore('data', () => {
// ref() คือการประกาศ state เหมือน vuex
const loader = ref<boolean>(false)
/**
* active tab
* @param val boolean false = close , true = open
*/
const loaderPage = (val: boolean) => {
loader.value = val
}
return {
loader,
loaderPage
}
})

View file

@ -2,6 +2,7 @@ import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import moment from 'moment'
import type { DataDateMonthObject } from '@/modules/01_exam/interface/index/Main'
import CustomComponent from '@/components/CustomDialog.vue'
export const useCounterMixin = defineStore('mixin', () => {
/**
@ -230,6 +231,74 @@ export const useCounterMixin = defineStore('mixin', () => {
}
}
const messageError = (q: any, e: any = '') => {
if (e.response !== undefined) {
if (e.response.data.status !== undefined) {
q.dialog({
component: CustomComponent,
componentProps: {
title: `พบข้อผิดพลาด`,
message: `${e.response.data.message}`,
icon: 'warning',
color: 'red',
onlycancel: true
}
})
} else {
q.dialog({
component: CustomComponent,
componentProps: {
title: `พบข้อผิดพลาด`,
message: `ข้อมูลผิดพลาดทำให้เกิดการไม่ตอบสนองต่อการเรียกใช้งานดูเว็บไซต์`,
icon: 'warning',
color: 'red',
onlycancel: true
}
})
}
} else {
q.dialog({
component: CustomComponent,
componentProps: {
title: `พบข้อผิดพลาด`,
message: `ข้อมูลผิดพลาดทำให้เกิดการไม่ตอบสนองต่อการเรียกใช้งานดูเว็บไซต์`,
icon: 'warning',
color: 'red',
onlycancel: true
}
})
}
}
const dialogMessage = (
// ไม่เอาใส่ undefined
q: any,
title: string,
message: string,
icon: string,
textOk: string,
color: string,
ok?: Function,
cancel?: Function
) => {
q.dialog({
component: CustomComponent,
componentProps: {
title: title,
message: message,
icon: icon,
color: color,
textOk: textOk
}
})
.onOk(() => {
if (ok != undefined) ok()
})
.onCancel(() => {
if (cancel != undefined) cancel()
})
}
function modalDelete(q: any, title: string, message: string, ok: Function, cancel?: Function) {
q.dialog({
title: `<span class="text-red">${title}</span>`,
@ -442,6 +511,7 @@ export const useCounterMixin = defineStore('mixin', () => {
modalDelete,
modalConfirm,
modalError,
statusCandidate
statusCandidate,
messageError
}
})