1404/11/04- first
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
|
||||
export function getConfigApp(key: string) {
|
||||
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user:{}
|
||||
|
||||
if (config) {
|
||||
return config[key]
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import { Modal } from 'ant-design-vue'
|
||||
import { createVNode } from 'vue'
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
|
||||
import { deleteUser } from '@/api/user'
|
||||
import { message } from 'ant-design-vue/es'
|
||||
|
||||
//todo
|
||||
export async function confirmDeleteItem(
|
||||
type: string,
|
||||
id: number,
|
||||
functionDelete: (id: number) => Promise<any>,
|
||||
refreshTable: () => void
|
||||
) {
|
||||
Modal.confirm({
|
||||
title: `آیا از حذف ${type} اطمینان دارید؟`,
|
||||
icon: createVNode(ExclamationCircleOutlined),
|
||||
okText: 'تایید',
|
||||
okType: 'danger',
|
||||
centered: true,
|
||||
cancelText: 'انصراف',
|
||||
async onOk() {
|
||||
// console.log('OK');
|
||||
// await deleteItem(id)
|
||||
|
||||
// loading.value = true
|
||||
// table?.value?.spinTable(true)
|
||||
// @ts-ignore
|
||||
try {
|
||||
await functionDelete(id)
|
||||
refreshTable()
|
||||
console.log('finall')
|
||||
message.success('با موفقیت حذف شد')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
// message.error('خطا در حذف')
|
||||
}
|
||||
|
||||
// setTimeout(Math.random() > 0.5 ? resolve : reject, 1000)
|
||||
// table?.value?.fetch()
|
||||
|
||||
// loading.value = false
|
||||
// table?.value?.spinTable(false)
|
||||
},
|
||||
onCancel() {
|
||||
console.log('Cancel')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function confirmActOnApi(
|
||||
title: string,
|
||||
item: any,
|
||||
functionApi: (item: any) => Promise<any>,
|
||||
refreshTable?: () => void
|
||||
) {
|
||||
Modal.confirm({
|
||||
title: title,
|
||||
icon: createVNode(ExclamationCircleOutlined),
|
||||
okText: 'تایید',
|
||||
okType: 'danger',
|
||||
centered: true,
|
||||
cancelText: 'انصراف',
|
||||
async onOk() {
|
||||
// console.log('OK');
|
||||
// await deleteItem(id)
|
||||
|
||||
// loading.value = true
|
||||
// table?.value?.spinTable(true)
|
||||
// @ts-ignore
|
||||
try {
|
||||
console.log('sasas')
|
||||
await functionApi(item)
|
||||
if (refreshTable) {
|
||||
refreshTable()
|
||||
}
|
||||
// console.log('finall')
|
||||
message.success('با موفقیت انجام شد')
|
||||
Modal.destroyAll()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
// message.error('خطا در حذف')
|
||||
}
|
||||
|
||||
// setTimeout(Math.random() > 0.5 ? resolve : reject, 1000)
|
||||
// table?.value?.fetch()
|
||||
|
||||
// loading.value = false
|
||||
// table?.value?.spinTable(false)
|
||||
},
|
||||
onCancel() {
|
||||
console.log('Cancel')
|
||||
Modal.destroyAll()
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { tokenName } from '@root/config'
|
||||
export const loading = ref<boolean>(false)
|
||||
export const loadingMore = ref<boolean>(false)
|
||||
|
||||
export function getToken() {
|
||||
return localStorage.getItem(tokenName)
|
||||
}
|
||||
|
||||
export async function setToken(token: string) {
|
||||
localStorage.setItem(tokenName, token)
|
||||
}
|
||||
|
||||
export async function setMyInfo(token: string) {
|
||||
localStorage.setItem(tokenName, token)
|
||||
}
|
||||
|
||||
/*export function getMyInfo() {
|
||||
return JSON.parse(localStorage.getItem('tamin_my_info') as string)
|
||||
}*/
|
||||
|
||||
export function removeToken() {
|
||||
return localStorage.removeItem(tokenName)
|
||||
}
|
||||
export function hotSelect(e: any) {
|
||||
e.target?.select()
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
export function inputRules(title?: string) {
|
||||
if (title) {
|
||||
return [{ required: true, message: `پر کردن ${title} الزامی است` }]
|
||||
} else {
|
||||
return [{ required: true, message: `پر کردن مورد بالا الزامی است` }]
|
||||
}
|
||||
}
|
||||
|
||||
export function inputRulesNumber(title?: string) {
|
||||
if (title) {
|
||||
return [
|
||||
{ required: true, message: `پر کردن ${title} الزامی است` },
|
||||
{
|
||||
required: true,
|
||||
type: 'regexp',
|
||||
pattern: /\d+/g,
|
||||
message: 'لطفا اطلاعات را به صورت عدد و نقطه وارد کنید'
|
||||
}
|
||||
]
|
||||
} else {
|
||||
return [
|
||||
{ required: true, message: `پر کردن مورد بالا الزامی است` },
|
||||
{
|
||||
required: true,
|
||||
type: 'regexp',
|
||||
pattern: /\d+/g,
|
||||
message: 'لطفا اطلاعات را به صورت عدد و نقطه وارد کنید'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export function inputLenRules(len: number, title?: string) {
|
||||
if (title) {
|
||||
return [
|
||||
{ required: true, message: `پر کردن ${title} الزامی است` },
|
||||
{ len: len, message: `تعداد کاراکتر باید ${len} عدد باشد` }
|
||||
]
|
||||
} else {
|
||||
return [
|
||||
{ required: true, message: 'پر کردن مورد بالا الزامی است' },
|
||||
{ len: len, message: `تعداد کاراکتر باید ${len} عدد باشد` }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export const valueValidation = computed(() => {
|
||||
const temp = inputRules()
|
||||
temp.push({ pattern: /^[A-Za-z]*$/, message: 'فقط حروف انگلیسی مجاز است' })
|
||||
return temp
|
||||
})
|
||||
Reference in New Issue
Block a user