Repository: yucccc/vue-pay-keyboard Branch: master Commit: 52c6cccbed19 Files: 11 Total size: 36.3 KB Directory structure: gitextract_0gykpxdb/ ├── .babelrc ├── .gitignore ├── README.md ├── dist/ │ └── vue-pay-keyboard.js ├── index.html ├── package.json ├── src/ │ ├── App.vue │ ├── lib/ │ │ ├── index.js │ │ └── vue-pay-keyboard.vue │ └── main.js └── webpack.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .babelrc ================================================ { "presets": [ ["env", { "modules": false }] ] } ================================================ FILE: .gitignore ================================================ .DS_Store node_modules/ npm-debug.log yarn-error.log # Editor directories and files .idea *.suo *.ntvs* *.njsproj *.sln ================================================ FILE: README.md ================================================ # vue-pay-keyboard A Vue component to pay-keyboard 一个虚拟数字支付键盘插件 [vue插件开发与发布](https://www.jianshu.com/p/d6855556cd75) ## demo演示 [demo](http://mall.yucccc.com/vuepayboard/) ## 安装 ```JS npm install vue-pay-keyboard -S ``` ## 使用 ```js // ES6 import vuePayKeyboard from 'vue-pay-keyboard.js' // require var vuePayKeyboard = require('PayKeyboard') Vue.use(vuePayKeyboard) // 或者直接使用script导入 // 作为组件的方式使用 ``` ### 配置 ```html
``` ```javascript methods:{ pasEnd(val) { console.log(val); //得到密码 可能会进行一些加密动作 setTimeout(() => { // 模拟请求接口验证密码中 .. if (val === '111111') { // 密码正确 this.$refs.pay.$payStatus(true) // 拿到子组件的事件 } else { this.$refs.pay.$payStatus(false) } }, 1000) } } ``` ### Props | name | Description | type |default| | ----------------- | ---------------- | :--------: | :----------: | | highlight-color | 点击时高亮颜色 |String| #000 | pas-digits | 密码位数 |Number | 6 | is-pay | 显示键盘 |Boolean | false | pay-title | 支付标题 |String | 请输入支付密码 ### Slots 支持自定义插槽 | name | Description | type |default| | ----------------- | ---------------- | :--------: | :----------: | | loading-ani | 支付请求中 || loading | pay-status | 支付成功或者失败|| 支付成功 ### Events | name | Description | | :--------: | ----- | | pas-end | 密码输入完毕后触发事件,接收所输密码 | close | 关闭键盘 ================================================ FILE: dist/vue-pay-keyboard.js ================================================ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("PayKeyboard",[],e):"object"==typeof exports?exports.PayKeyboard=e():t.PayKeyboard=e()}(this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/dist/",e(e.s=2)}([function(t,e,n){function i(t){n(7)}var o=n(5)(n(1),n(6),i,"data-v-7c990886",null);t.exports=o.exports},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=null;e.default={name:"vue-pay-keyboard",props:{payTitle:{type:String,default:"请输入支付密码"},highlightColor:{type:String,default:"#ccc"},pasDigits:{type:Number,default:6},isPay:{type:Boolean,default:!1}},data:function(){return{keyShow:!0,lodingShow:!1,paySuc:!1,val:[],keyList:[[1,2,3],[4,6,6],[7,8,9]],payStatus:!1}},computed:{payStatusText:function(){return this.payStatus?"支付成功!":"支付失败,请重输密码!"}},methods:{inputEnd:function(t,e){this.unhighLight(t.currentTarget,e)},unhighLight:function(t,e){t.style.backgroundColor=e?"#e8e8e8":"#fff"},highlight:function(t){t.style.backgroundColor=this.highlightColor},inputStart:function(t,e){this.val.length0&&this.val.pop()},close:function(){this.$emit("close")},$payStatus:function(t){var e=this;"boolean"==typeof t&&(this.payStatus=t,this.lodingShow=!1,this.paySuc=!0,i=t?setTimeout(function(){clearTimeout(i),e.$emit("close"),e.keyShow=!0,e.paySuc=!1,e.$refs.loading.classList.remove("loading-ani")},800):setTimeout(function(){clearTimeout(i),e.keyShow=!0,e.paySuc=!1,e.$refs.loading.classList.remove("loading-ani")},800))}}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=n(0),o=n.n(i),a={install:function(t,e){t.component(o.a.name,o.a)}};"undefined"!=typeof window&&window.Vue&&window.Vue.use(a),e.default=a},function(t,e,n){e=t.exports=n(4)(),e.push([t.i,'div[data-v-7c990886],input[data-v-7c990886],span[data-v-7c990886]{-o-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}input[data-v-7c990886]{background:none;outline:none;border:none;background-color:transparent;border-color:transparent;-webkit-appearance:none}@keyframes loadingRotate-data-v-7c990886{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}.title[data-v-7c990886]{text-align:center;height:50px;line-height:50px;margin-bottom:25px;position:relative}.pa[data-v-7c990886]{position:absolute;right:15px;top:50%;transform:translateY(-50%);display:flex;align-content:center;justify-content:center}.loading[data-v-7c990886]{display:flex;align-items:center;justify-content:center}.loading-ani[data-v-7c990886]{animation:loadingRotate-data-v-7c990886 .8s infinite}.pay-box[data-v-7c990886]{z-index:111;position:fixed;left:0;top:0;width:100%;height:100%;overflow-x:hidden;overflow-y:hidden;background-color:rgba(0,0,0,.5);z-index:999}.pay-box>div[data-v-7c990886]{position:absolute;width:100%;height:68%;left:0;bottom:0;color:#363636;background-color:#fff}.v-1px-b[data-v-7c990886],.v-1px-l[data-v-7c990886],.v-1px-t[data-v-7c990886],.v-1px[data-v-7c990886]{position:relative}.v-1px-b[data-v-7c990886]:after{content:" ";bottom:0;border-bottom:1px solid #c7c7c7;transform-origin:0 100%}.v-1px-b[data-v-7c990886]:after,.v-1px-t[data-v-7c990886]:before{position:absolute;left:0;right:0;height:1px;color:#c7c7c7;transform:scaleY(.5)}.v-1px-t[data-v-7c990886]:before{z-index:112;top:0;content:"";border-top:1px solid #c7c7c7;transform-origin:0 0}.v-1px-l[data-v-7c990886]:before{position:absolute;left:0;top:0;bottom:0;width:1px;content:"";border-left:1px solid #c7c7c7;transform:scaleX(.5);color:#c7c7c7;transform-origin:0 0}.v-1px[data-v-7c990886]:before{position:absolute;left:0;top:0;width:200%;height:200%;content:"";border:1px solid #c7c7c7;transform:scale(.5);color:#c7c7c7;transform-origin:left top;z-index:1000}.key-box[data-v-7c990886]{position:absolute;left:0;bottom:0;width:100%;font-size:16px;color:#363636}.key-box .item[data-v-7c990886]{display:flex;text-align:center;line-height:50px;height:50px}.key-box .key[data-v-7c990886]{cursor:pointer;width:100%;height:100%;flex:1}.pas-box[data-v-7c990886]{width:80%;height:45px;display:flex;margin:0 auto;line-height:45px;text-align:center}.pas-box>div[data-v-7c990886]{flex:1;display:flex;align-items:center;justify-content:center}.pas-box>div>input[data-v-7c990886]{width:100%;font-size:18px;text-align:center;height:100%;display:block}.slide-enter-active[data-v-7c990886]{transition:all 10s ease}.slide-enter[data-v-7c990886]{transform:translateY(500px)}',""])},function(t,e){t.exports=function(){var t=[];return t.toString=function(){for(var t=[],e=0;e0}},[n("input",{attrs:{type:"password",disabled:""},domProps:{value:t.val[i]}})])})),t._v(" "),t.keyShow?n("div",{staticClass:"key-box"},[t._l(t.keyList,function(e,i){return n("div",{key:i,staticClass:"item v-1px-t"},t._l(e,function(e,i){return n("div",{key:i,staticClass:"key",class:{"v-1px-l":0!=i},on:{touchstart:function(n){t.inputStart(e,n)},touchend:function(e){t.inputEnd(e)}}},[t._v("\n "+t._s(e)+"\n ")])}))}),t._v(" "),n("div",{staticClass:"item v-1px-t"},[n("div",{staticClass:"key ",staticStyle:{background:"#e8e8e8"}}),t._v(" "),n("div",{staticClass:"key v-1px-l",on:{touchstart:function(e){t.inputStart(0,e)},touchend:function(e){t.inputEnd(e)}}},[t._v("0\n ")]),t._v(" "),n("div",{staticClass:"key v-1px-l",staticStyle:{background:"#e8e8e8"},on:{touchstart:function(e){t.del(e)},touchend:function(e){t.inputEnd(e,"del")}}},[t._v("-\n ")])])],2):t._e(),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:t.paySuc,expression:"paySuc"}],staticStyle:{"text-align":"center"}},[t._t("pay-status",[t._v("\n "+t._s(t.payStatusText)+"\n ")])],2),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:t.lodingShow,expression:"lodingShow"}],ref:"loading",staticClass:"loading"},[t._t("loading-ani",[n("svg",{staticClass:"icon",attrs:{t:"1501508156392",viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","p-id":"1936","xmlns:xlink":"http://www.w3.org/1999/xlink",width:"100",height:"100"}},[n("path",{attrs:{d:"M914.9 682.1c-22 52.1-53.5 98.8-93.7 139s-86.9 71.7-139 93.7c-53.9 22.8-111.1 34.3-170.2 34.3s-116.3-11.5-170.1-34.3c-52.1-22-98.8-53.5-139-93.7s-71.7-86.9-93.7-139C86.4 628.3 74.8 571.1 74.8 512s11.5-116.3 34.3-170.2c22-52.1 53.5-98.8 93.7-139s86.9-71.7 139-93.7c43.3-18.3 88.8-29.4 135.7-33C497 74.6 512 58.4 512 38.9l0 0c0-21.8-18.6-39-40.3-37.3C207.8 22.1 0 242.8 0 512c0 282.8 229.2 512 512 512 269.2 0 489.9-207.8 510.4-471.7 1.7-21.7-15.5-40.3-37.3-40.3l0 0c-19.5 0-35.8 15-37.3 34.4C944.2 593.3 933.2 638.8 914.9 682.1z","p-id":"1937",fill:"#6A8FE5"}})])])],2)]):t._e()]):t._e()},staticRenderFns:[]}},function(t,e,n){var i=n(3);"string"==typeof i&&(i=[[t.i,i,""]]),i.locals&&(t.exports=i.locals);n(8)("5601c310",i,!0,{})},function(t,e,n){function i(t){for(var e=0;en.parts.length&&(i.parts.length=n.parts.length)}else{for(var r=[],o=0;o vue-pay-keyboard
================================================ FILE: package.json ================================================ { "name": "vue-pay-keyboard", "description": "A Vue component to pay-keyboard", "version": "1.1.5", "author": "yucccc <13450003105@163.com>", "private": false, "license": "MIT", "main": "dist/vue-pay-keyboard.js", "scripts": { "dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot", "build": "cross-env NODE_ENV=production webpack --progress --hide-modules", "pub": "npm run build && npm publish" }, "dependencies": { "vue": "^2.3.3", "vue-pay-keyboard": "^1.1.2" }, "repository": { "type": "git", "url": "https://github.com/yucccc/vue-pay-keyboard" }, "devDependencies": { "babel-core": "^6.0.0", "babel-loader": "^6.0.0", "babel-preset-env": "^1.5.1", "cross-env": "^3.0.0", "css-loader": "^0.25.0", "file-loader": "^0.9.0", "node-sass": "^4.5.0", "sass-loader": "^5.0.1", "vue-loader": "^12.1.0", "vue-template-compiler": "^2.3.3", "webpack": "^2.6.1", "webpack-dev-server": "^2.4.5" } } ================================================ FILE: src/App.vue ================================================ ================================================ FILE: src/lib/index.js ================================================ import vuePayKeyboard from './vue-pay-keyboard.vue' // 导入组件 const paykeyboard = { install(Vue, options) { Vue.component(vuePayKeyboard.name, vuePayKeyboard) // vuePayKeyboard.name 组件的name属性 // 类似通过 this.$xxx 方式调用插件的 其实只是挂载到原型上而已 // Vue.prototype.$xxx // 最终可以在任何地方通过 this.$xxx 调用 // 虽然没有明确规定用$开头 但是大家都默认遵守这个规定 } } if (typeof window !== 'undefined' && window.Vue) { window.Vue.use(paykeyboard); } export default paykeyboard // 导出.. ================================================ FILE: src/lib/vue-pay-keyboard.vue ================================================ ================================================ FILE: src/main.js ================================================ import Vue from 'vue' import App from './App.vue' import vuePayKeyboard from './lib/index.js' // import vuePayKeyboard from './lib/indexvue-pay-keyboard' Vue.use(vuePayKeyboard) new Vue({ el: '#app', render: h => h(App) }) ================================================ FILE: webpack.config.js ================================================ 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-pay-keyboard.js', // 我们可不想打包后叫build 多low啊 起一个与项目相对应的 library: 'PayKeyboard', // library指定的就是你使用require时的模块名,这里便是require("PayKeyboard") libraryTarget: 'umd', //libraryTarget会生成不同umd的代码,例如可以只是commonjs标准的,也可以是指amd标准的,也可以只是通过script标签引入的。 umdNamedDefine: true // 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define。 }, module: { // loader rules: [{ 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' } }, devServer: { historyApiFallback: true, noInfo: true }, performance: { hints: false }, devtool: '#eval-source-map' // 生成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 }) ]) }