mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-25 14:37:40 +08:00
初始化admin pc端
This commit is contained in:
9
admin/src/core/directives/index.ts
Normal file
9
admin/src/core/directives/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { App } from 'vue'
|
||||
|
||||
const modules = import.meta.globEager('./modules/*.ts')
|
||||
export default (app: App<Element>) => {
|
||||
Object.keys(modules).forEach(key => {
|
||||
const name = key.replace(/^\.\/(.*)\.\w+$/, '$1')
|
||||
app.directive(name, modules[key].default)
|
||||
})
|
||||
}
|
||||
32
admin/src/core/directives/modules/copy.ts
Normal file
32
admin/src/core/directives/modules/copy.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* copy 复制指令(用于复制文本)
|
||||
* 指令用法:
|
||||
* <el-button v-copy="copyValue">复制</el-button>
|
||||
* copyValue为需要复制的值
|
||||
*/
|
||||
|
||||
import { ElMessage } from 'element-plus'
|
||||
import Clipboard from 'clipboard'
|
||||
;(function copyboard() {
|
||||
const clipboard = new Clipboard('.copy-btn')
|
||||
|
||||
clipboard.on('success', e => {
|
||||
ElMessage.success('复制成功')
|
||||
e.clearSelection()
|
||||
})
|
||||
|
||||
clipboard.on('error', err => {
|
||||
console.error(err)
|
||||
ElMessage.success('复制失败')
|
||||
})
|
||||
})()
|
||||
|
||||
export default {
|
||||
mounted: (el: HTMLElement, binding: any) => {
|
||||
el.className = el.className + ' copy-btn'
|
||||
el.setAttribute('data-clipboard-text', binding.value)
|
||||
},
|
||||
updated: (el: HTMLElement, binding: any) => {
|
||||
el.setAttribute('data-clipboard-text', binding.value)
|
||||
}
|
||||
}
|
||||
14
admin/src/core/hooks/app.ts
Normal file
14
admin/src/core/hooks/app.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useStore } from '@/store'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
export function useAdmin() {
|
||||
const store = useStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
return {
|
||||
store,
|
||||
route,
|
||||
router
|
||||
}
|
||||
}
|
||||
68
admin/src/core/hooks/pages.ts
Normal file
68
admin/src/core/hooks/pages.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { deepClone } from '@/utils/util'
|
||||
import { reactive, toRaw } from 'vue'
|
||||
|
||||
// 分页钩子函数
|
||||
interface Options {
|
||||
page?: number
|
||||
size?: number
|
||||
callback: (_arg: any) => Promise<any>
|
||||
params?: Record<any, any>
|
||||
}
|
||||
|
||||
let paramsInit: Record<any, any> = {}
|
||||
|
||||
export function usePages(options: Options) {
|
||||
const { page = 1, size = 15, callback, params = {} } = options
|
||||
// 记录分页初始参数
|
||||
paramsInit = Object.assign({}, toRaw(params))
|
||||
// 分页数据
|
||||
const pager = reactive({
|
||||
page,
|
||||
size,
|
||||
loading: false,
|
||||
count: 0,
|
||||
lists: [] as any[]
|
||||
})
|
||||
// 请求分页接口
|
||||
const requestApi = () => {
|
||||
// 禁止并发请求
|
||||
if (pager.loading) {
|
||||
return Promise.reject()
|
||||
}
|
||||
pager.loading = true
|
||||
return callback({
|
||||
page_no: pager.page,
|
||||
page_size: pager.size,
|
||||
...params
|
||||
})
|
||||
.then((res: any) => {
|
||||
pager.count = res?.count
|
||||
pager.lists = res?.lists
|
||||
return Promise.resolve(res)
|
||||
})
|
||||
.catch((err: any) => {
|
||||
return Promise.reject(err)
|
||||
})
|
||||
.finally(() => {
|
||||
pager.loading = false
|
||||
})
|
||||
}
|
||||
// 重置为第一页
|
||||
const resetPage = () => {
|
||||
pager.page = 1
|
||||
requestApi()
|
||||
}
|
||||
// 重置参数
|
||||
const resetParams = () => {
|
||||
Object.keys(paramsInit).forEach(item => {
|
||||
params[item] = paramsInit[item]
|
||||
})
|
||||
requestApi()
|
||||
}
|
||||
return {
|
||||
pager,
|
||||
requestApi,
|
||||
resetParams,
|
||||
resetPage
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user