Commit 90a77255 by 无尘

add:增加上传图片预览插件

parent 450b9731
{
"presets": [
["env", { "modules": false }],
"stage-3"
]
}
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
.DS_Store
node_modules/
npm-debug.log
yarn-error.log
package-lock.json
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
# *src
# 预览插件 # vue-gic-img-preview
\ No newline at end of file
> A Vue.js vue-gic-img-preview Plugin
## Install
```shell
npm install @gic-test/vue-gic-img-preview -S
```
## how to use
```
// main.js
import vueGicImgPreview from 'vue-gic-img-preview'
Vue.use(vueGicImgPreview)
// 使用页面
<img :src="src" alt="img" @mouseover="showImage(src)"/> // 图片所在标签, 图片 src 参数随各个调用地方
<vue-gic-img-preview :imgUrl="imgUrl" :imgShowFlag="imgShowFlag" @hideImage="hideImage"></vue-gic-img-preview>
data() {
return {
// 可传参数
imgShowFlag: false, // 是否弹框显示,true: 显示;false: 不显示
imgUrl: '', // 传递的图片 src
}
}
methods: {
showImage(src) {
var that = this
if(!src || src == ''){
return false;
}
that.imgShowFlag = true;
that.imgUrl = src;
},
hideImage(val) {
var that = this
that.imgShowFlag = val
}
},
```
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("vue-gic-img-preview",[],t):"object"==typeof exports?exports["vue-gic-img-preview"]=t():e["vue-gic-img-preview"]=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/",t(t.s=1)}([function(e,t,n){"use strict";t.a={name:"vue-gic-img-preview",props:{imgUrl:String,imgShowFlag:Boolean},data:function(){return{showFlag:!1,imgSrc:""}},methods:{hideImage:function(){var e=this;e.showFlag=!1,e.$emit("hideImage",e.showFlag)},hidePanel:function(){var e=this;e.showFlag&&e.hideImage()}},watch:{imgUrl:function(e){this.imgSrc=e},imgShowFlag:function(e){this.showFlag=e}},mounted:function(){var e=this;e.imgSrc=this.imgUrl,this.showFlag=e.imgShowFlag,document.addEventListener("click",e.hidePanel,!1)}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(2),i={install:function(e,t){e.component(r.a.name,r.a)}};"undefined"!=typeof window&&window.Vue&&window.Vue.use(i),t.default=i},function(e,t,n){"use strict";function r(e){n(3)}var i=n(0),o=n(9),a=n(8),s=r,c=a(i.a,o.a,!1,s,"data-v-1e11a38c",null);t.a=c.exports},function(e,t,n){var r=n(4);"string"==typeof r&&(r=[[e.i,r,""]]),r.locals&&(e.exports=r.locals);n(6)("333acad7",r,!0,{})},function(e,t,n){t=e.exports=n(5)(!1),t.push([e.i,".image-view-contain[data-v-1e11a38c]{position:relative;width:100%}.image-view-body[data-v-1e11a38c]{position:fixed;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);z-index:5000;display:-webkit-flex;display:flex;justify-content:center;align-items:center;padding:24px;background:#fff;text-align:center;border-radius:4px;-webkit-box-shadow:0 4px 12px rgba(0,0,0,.15);box-shadow:0 4px 12px rgba(0,0,0,.15);overflow:hidden;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.el-icon-close[data-v-1e11a38c]{position:absolute;top:10px;right:10px;font-size:14px;color:#909399;cursor:pointer}.image-view-body img[data-v-1e11a38c]{max-width:452px;max-height:452px}.image-view-mask[data-v-1e11a38c]{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,.5);z-index:2000}",""])},function(e,t){function n(e,t){var n=e[1]||"",i=e[3];if(!i)return n;if(t&&"function"==typeof btoa){var o=r(i);return[n].concat(i.sources.map(function(e){return"/*# sourceURL="+i.sourceRoot+e+" */"})).concat([o]).join("\n")}return[n].join("\n")}function r(e){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e))))+" */"}e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var r=n(t,e);return t[2]?"@media "+t[2]+"{"+r+"}":r}).join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var r={},i=0;i<this.length;i++){var o=this[i][0];"number"==typeof o&&(r[o]=!0)}for(i=0;i<e.length;i++){var a=e[i];"number"==typeof a[0]&&r[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),t.push(a))}},t}},function(e,t,n){function r(e){for(var t=0;t<e.length;t++){var n=e[t],r=d[n.id];if(r){r.refs++;for(var i=0;i<r.parts.length;i++)r.parts[i](n.parts[i]);for(;i<n.parts.length;i++)r.parts.push(o(n.parts[i]));r.parts.length>n.parts.length&&(r.parts.length=n.parts.length)}else{for(var a=[],i=0;i<n.parts.length;i++)a.push(o(n.parts[i]));d[n.id]={id:n.id,refs:1,parts:a}}}}function i(){var e=document.createElement("style");return e.type="text/css",f.appendChild(e),e}function o(e){var t,n,r=document.querySelector("style["+m+'~="'+e.id+'"]');if(r){if(g)return h;r.parentNode.removeChild(r)}if(b){var o=p++;r=l||(l=i()),t=a.bind(null,r,o,!1),n=a.bind(null,r,o,!0)}else r=i(),t=s.bind(null,r),n=function(){r.parentNode.removeChild(r)};return t(e),function(r){if(r){if(r.css===e.css&&r.media===e.media&&r.sourceMap===e.sourceMap)return;t(e=r)}else n()}}function a(e,t,n,r){var i=n?"":r.css;if(e.styleSheet)e.styleSheet.cssText=x(t,i);else{var o=document.createTextNode(i),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(o,a[t]):e.appendChild(o)}}function s(e,t){var n=t.css,r=t.media,i=t.sourceMap;if(r&&e.setAttribute("media",r),v.ssrId&&e.setAttribute(m,t.id),i&&(n+="\n/*# sourceURL="+i.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */"),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}var c="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!c)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var u=n(7),d={},f=c&&(document.head||document.getElementsByTagName("head")[0]),l=null,p=0,g=!1,h=function(){},v=null,m="data-vue-ssr-id",b="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());e.exports=function(e,t,n,i){g=n,v=i||{};var o=u(e,t);return r(o),function(t){for(var n=[],i=0;i<o.length;i++){var a=o[i],s=d[a.id];s.refs--,n.push(s)}t?(o=u(e,t),r(o)):o=[];for(var i=0;i<n.length;i++){var s=n[i];if(0===s.refs){for(var c=0;c<s.parts.length;c++)s.parts[c]();delete d[s.id]}}}};var x=function(){var e=[];return function(t,n){return e[t]=n,e.filter(Boolean).join("\n")}}()},function(e,t){e.exports=function(e,t){for(var n=[],r={},i=0;i<t.length;i++){var o=t[i],a=o[0],s=o[1],c=o[2],u=o[3],d={id:e+":"+i,css:s,media:c,sourceMap:u};r[a]?r[a].parts.push(d):n.push(r[a]={id:a,parts:[d]})}return n}},function(e,t){e.exports=function(e,t,n,r,i,o){var a,s=e=e||{},c=typeof e.default;"object"!==c&&"function"!==c||(a=e,s=e.default);var u="function"==typeof s?s.options:s;t&&(u.render=t.render,u.staticRenderFns=t.staticRenderFns,u._compiled=!0),n&&(u.functional=!0),i&&(u._scopeId=i);var d;if(o?(d=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(o)},u._ssrRegister=d):r&&(d=r),d){var f=u.functional,l=f?u.render:u.beforeCreate;f?(u._injectStyles=d,u.render=function(e,t){return d.call(t),l(e,t)}):u.beforeCreate=l?[].concat(l,d):[d]}return{esModule:a,exports:s,options:u}}},function(e,t,n){"use strict";var r=function(){var e=this,t=e.$createElement,n=e._self._c||t;return e.showFlag?n("div",{staticClass:"image-view-contain"},[n("transition",{attrs:{name:"fade"}},[n("div",{staticClass:"image-view-body",on:{click:function(t){return t.stopPropagation(),e.hideImage(t)}}},[n("i",{staticClass:"el-icon-close"}),e._v(" "),n("img",{attrs:{src:e.imgSrc,alt:""}})])])],1):e._e()},i=[],o={render:r,staticRenderFns:i};t.a=o}])});
//# sourceMappingURL=vue-gic-img-preview.js.map
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>vue-images-toasts</title>
</head>
<body>
<div id="app"></div>
<!-- <script src="/dist/build.js"></script> -->
<script src="/dist/vue-images-toasts.js"></script>
</body>
</html>
{
"name": "@gic-test/vue-gic-img-preview",
"description": "vue-gic-img-preview Plugin",
"version": "1.0.12",
"license": "MIT",
"private": false,
"author": "fairyly",
"main": "dist/vue-gic-img-preview.js",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"vue": "^2.5.11"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
<template>
<div id="app">
<vue-gic-img-preview :imgUrl="imgUrl" :imgShowFlag="imgShowFlag" @hideImage="hideImage"></vue-gic-img-preview>
</div>
</template>
<script>
import vueGicImgPreview from './lib/vue-gic-img-preview'
export default {
name: 'app',
data () {
return {
imgShowFlag: false, // 是否弹框显示,true: 显示;false: 不显示
imgUrl: '', // 传递的图片 src
}
},
components: {
vueGicImgPreview
},
methods: {
showImage(src) {
var that = this
if(!src || src == ''){
return false;
}
that.imgShowFlag = true;
that.imgUrl = src;
},
hideImage(val) {
var that = this
that.imgShowFlag = val
}
}
}
</script>
<style lang="scss">
* {
margin: 0;
padding: 0;
}
</style>
import vueGicImgPreview from './vue-gic-img-preview.vue' // 导入组件
const ImgPreview = {
install(Vue, options) {
Vue.component(vueGicImgPreview.name, vueGicImgPreview) // vueImagesToast.name 组件的name属性
// 类似通过 this.$xxx 方式调用插件的 其实只是挂载到原型上而已
// Vue.prototype.$xxx // 最终可以在任何地方通过 this.$xxx 调用
// 虽然没有明确规定用$开头 但是大家都默认遵守这个规定
}
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(ImgPreview);
}
export default ImgPreview
// export {
// vueImagesToasts
// }
<template>
<div class="image-view-contain" v-if="showFlag">
<!-- <div class="image-view-mask" @click.stop="hideImage"></div> -->
<transition name="fade">
<div class="image-view-body" @click.stop="hideImage">
<i class="el-icon-close"></i>
<img :src="imgSrc" alt=""/>
</div>
</transition>
</div>
</template>
<script>
export default {
name: 'vue-gic-img-preview',
props:{
imgUrl: String,
imgShowFlag: Boolean
},
data () {
return {
showFlag: false,
imgSrc: '',
}
},
methods:{
hideImage() {
var that = this
that.showFlag = false
that.$emit('hideImage',that.showFlag)
},
hidePanel() {
var that = this
if (!!that.showFlag) {
that.hideImage()
}
}
},
watch:{
imgUrl:function(newVal) {
this.imgSrc = newVal
},
imgShowFlag:function(newVal) {
this.showFlag = newVal
},
},
mounted() {
var that = this
that.imgSrc = this.imgUrl;
this.showFlag = that.imgShowFlag;
// 监听点击隐藏弹层
document.addEventListener('click', that.hidePanel, false)
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.image-view-contain {
position: relative;
width: 100%;
}
.image-view-body {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
z-index: 5000;
display: -webkit-flex;
display: flex;
justify-content: center;
align-items: center;
/*width: 520px;
height: 520px;*/
padding: 24px;
background: #fff;
text-align: center;
border-radius: 4px;
-webkit-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
overflow: hidden;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.el-icon-close {
position: absolute;
top: 10px;
right: 10px;
font-size: 14px;
color: #909399;
cursor: pointer;
}
.image-view-body img {
/*-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
-o-flex: 1;
flex: 1;*/
max-width: 452px;
max-height: 452px;
}
.image-view-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,.5);
z-index: 2000;
}
</style>
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
var path = require('path')
var webpack = require('webpack')
module.exports = {
// entry: './src/main.js',
entry: './src/lib/index.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
// filename: 'build.js',
filename: 'vue-gic-img-preview.js',
library: 'vue-gic-img-preview',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment