Skip to content

Commit 8842463

Browse files
committed
编写自定义指令
1 parent 53e832a commit 8842463

File tree

17 files changed

+81
-202
lines changed

17 files changed

+81
-202
lines changed

.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module.exports = {
1010
es6: true,
1111
},
1212
extends: ['plugin:vue/recommended', 'eslint:recommended'],
13-
13+
// 设置可以使用的全局变量
14+
globals: {"tpwidget": true},
1415
// add your custom rules here
1516
//it is base on https://github.com/vuejs/eslint-config-vue
1617
rules: {

src/components/PageTable/index.vue

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<!-- 图片 -->
7070
<img
7171
v-else-if="item.type === 'image' && scope.row[item.value]"
72+
v-imgAlart
7273
height="50px"
7374
:src="scope.row[item.value]"
7475
>

src/directive/clipboard/clipboard.js

-49
This file was deleted.

src/directive/clipboard/index.js

-13
This file was deleted.

src/directive/el-dragDialog/drag.js

-77
This file was deleted.

src/directive/el-dragDialog/index.js

-13
This file was deleted.

src/directive/focus/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
install (Vue) {
3+
Vue.directive('focus', {
4+
inserted: el => {
5+
el.focus()
6+
}
7+
})
8+
}
9+
}

src/directive/imgAlart/alart.css

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.g-img-alart{
2+
}
3+
.g-img-alart-mask{
4+
position: fixed;
5+
top: 0;
6+
left: 0;
7+
right: 0;
8+
bottom: 0;
9+
background: rgba(0, 0, 0, .5);
10+
z-index: 9999;
11+
}
12+
.g-img-alart-content{
13+
padding: 10px;
14+
position: fixed;
15+
top: 50%;
16+
left: 50%;
17+
z-index: 10001;
18+
transform: translate(-50%, -50%);
19+
background: white;
20+
border-radius: 10px;
21+
}
22+
.g-img-alart-img{
23+
max-width: 500px;
24+
}

src/directive/imgAlart/alart.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import './alart.css'
2+
export default {
3+
bind (el, binding) {
4+
el.addEventListener('click', e => {
5+
const src = e.target.currentSrc
6+
const body = document.querySelector('body')
7+
const imgAlart = document.createElement('div')
8+
imgAlart.className = 'g-img-alart'
9+
imgAlart.innerHTML = `
10+
<div class="g-img-alart-mask"></div>
11+
<div class="g-img-alart-content">
12+
<img class="g-img-alart-img" src="${src}">
13+
</div>
14+
`
15+
body.appendChild(imgAlart)
16+
17+
// 监听到遮罩层点击
18+
imgAlart.addEventListener('click', e => {
19+
if (e.target.className === 'g-img-alart-mask') {
20+
body.removeChild(imgAlart)
21+
}
22+
}, false)
23+
}, false)
24+
}
25+
}

src/directive/imgAlart/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import imgAlart from './alart'
2+
3+
export default {
4+
install (Vue) {
5+
Vue.directive('imgAlart', imgAlart)
6+
}
7+
}

src/directive/permission/index.js

-13
This file was deleted.

src/directive/permission/permission.js

-23
This file was deleted.

src/directive/waves/index.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import waves from './waves'
22

3-
const install = function (Vue) {
4-
Vue.directive('waves', waves)
3+
export default {
4+
install (Vue) {
5+
Vue.directive('waves', waves)
6+
}
57
}
6-
7-
if (window.Vue) {
8-
window.waves = waves
9-
Vue.use(install); // eslint-disable-line
10-
}
11-
12-
waves.install = install
13-
export default waves

src/main.js

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import '@/common/style/index.scss' // 自定义样式
1515
import mavonEditor from 'mavon-editor'
1616
import 'mavon-editor/dist/css/index.css'
1717
import vueWaves from '@/directive/waves/index'// 水波纹指令
18+
import vueFocus from '@/directive/focus/index'// 聚焦指令
19+
import vueImgAlart from '@/directive/imgAlart/index'// 图片弹窗指令
1820
import '@/common/config/errorLog' // 错误日志
1921
import '@/common/config/permission' // 路由动态配置
2022
import commonPlug from '@/common/js/commonPlug' // 自定义插件
@@ -23,6 +25,8 @@ Vue.use(commonPlug)
2325
Vue.use(ElementUI)
2426
Vue.use(mavonEditor)
2527
Vue.use(vueWaves)
28+
Vue.use(vueFocus)
29+
Vue.use(vueImgAlart)
2630
Vue.config.productionTip = false
2731

2832
/* eslint-disable no-new */

src/views/bbsConfig/carousel/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export default {
154154
data: [],
155155
fieldList: [
156156
{ label: '标题', value: 'title' },
157-
{ label: '图标', value: 'image', type: 'image', width: 100 },
157+
{ label: '图片', value: 'image', type: 'image', width: 100 },
158158
{ label: '排序', value: 'sort', width: 80 },
159159
{ label: '点击触发', value: 'click', type: 'select', list: 'eventList', minWidth: 120 },
160160
{ label: '跳转地址', value: 'href', minWidth: 120 },

src/views/layout/components/Navbar.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<template v-slot:form-avatar>
5757
<div class="slot-avatar">
5858
<img
59+
v-imgAlart
5960
:src="formInfo.data.avatar"
6061
style="height: 30px;"
6162
>
@@ -302,8 +303,8 @@ export default {
302303
},
303304
// 触发事件
304305
handleEvent (event, data) {
305-
switch (event) {
306-
}
306+
// switch (event) {
307+
// }
307308
}
308309
}
309310
}

src/views/sysMan/userMan/index.vue

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<template v-slot:form-avatar>
6969
<div class="slot-avatar">
7070
<img
71+
v-imgAlart
7172
:src="formInfo.data.avatar"
7273
style="height: 30px;"
7374
>

0 commit comments

Comments
 (0)