mirror of
https://github.com/javaLuo/vue-flip-down.git
synced 2025-04-05 03:05:03 +08:00
update
This commit is contained in:
parent
de8613a6da
commit
532d04e2b4
77
.gitignore
vendored
77
.gitignore
vendored
@ -1,62 +1,23 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
yarn.lock
|
||||
pnpm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
201
LICENSE
201
LICENSE
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
@ -5,6 +5,10 @@
|
||||
这是一个简单的翻页倒计时vue组件,项目中有用到,所以提取了一下。<br/>
|
||||
你们也可以直接把`src/app.vue`文件拷贝到项目里直接用,就是个普通vue组件,就不用`npm install` 了
|
||||
|
||||
# 注意:vue2.x 和 vue3.x
|
||||
**vue-flip-down 1.x的版本仅适用于vue2.x**<br/>
|
||||
**vue-flip-down 3.x的版本仅适用于vue3.x**
|
||||
|
||||
### 示例
|
||||

|
||||
|
||||
@ -16,10 +20,6 @@
|
||||
```
|
||||
npm install vue-flip-down --save
|
||||
```
|
||||
或
|
||||
```
|
||||
yarn add vue-flip-down
|
||||
```
|
||||
|
||||
### 使用
|
||||
```vue
|
||||
|
3
babel.config.js
Normal file
3
babel.config.js
Normal file
@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
presets: ["@vue/cli-plugin-babel/preset"],
|
||||
};
|
1
dist/main.js
vendored
1
dist/main.js
vendored
File diff suppressed because one or more lines are too long
@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"
|
||||
/>
|
||||
<title>Example</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="bundle.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,8 +1,4 @@
|
||||
import Vue from 'vue';
|
||||
import App from './src/app.vue';
|
||||
import { createApp } from "vue";
|
||||
import App from "./src/app.vue";
|
||||
|
||||
Vue.config.productionTip = false;
|
||||
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
}).$mount('#root');
|
||||
createApp(App).mount("#app");
|
||||
|
12
example/public/index.html
Normal file
12
example/public/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
|
||||
<title>Example</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
@ -1,34 +1,47 @@
|
||||
<template>
|
||||
<div>
|
||||
<CountDown :endDate="endDate" :type="type" :theme="1" :timeUnit="['天', '时', '分', '秒']" @timeUp="onTimeUp" />
|
||||
<AuthModelMy :show="isShow"
|
||||
@close="onClose" @success="onSuccess" @fail="onFail"/>
|
||||
|
||||
<hr />
|
||||
<input v-model="type" />
|
||||
<input v-model="endDate" />
|
||||
<div>{{ timeUp }}</div>
|
||||
<button @click="onShow">开始验证</button>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
// import CountDown from "../../dist/main.js";
|
||||
import CountDown from "../../src/index.js";
|
||||
import { ref } from "vue";
|
||||
import AuthModelMy from "../../dist/vue3-puzzle-vcode.umd.min.js";
|
||||
// import AuthModelMy from "../../src/app.vue";
|
||||
import Img1 from "./assets/1.jpg";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
timeUp: false,
|
||||
type: 2,
|
||||
endDate: new Date().getTime() + 5000,
|
||||
};
|
||||
},
|
||||
|
||||
components: {
|
||||
CountDown,
|
||||
},
|
||||
methods: {
|
||||
onTypeChange(t) {
|
||||
this.type = t;
|
||||
},
|
||||
onTimeUp() {
|
||||
this.timeUp = true;
|
||||
},
|
||||
AuthModelMy
|
||||
},
|
||||
setup(){
|
||||
const isShow = ref(false);
|
||||
const onShow = () => {
|
||||
isShow.value = true;
|
||||
}
|
||||
const onClose = () => {
|
||||
isShow.value = false;
|
||||
}
|
||||
|
||||
const onSuccess = (e) => {
|
||||
console.log('验证成功:', e);
|
||||
onClose();
|
||||
}
|
||||
|
||||
const onFail = (e) => {
|
||||
console.log('验证失败:', e);
|
||||
onClose();
|
||||
}
|
||||
return {
|
||||
isShow,
|
||||
onShow,
|
||||
onClose,
|
||||
onSuccess,
|
||||
onFail
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</script>
|
BIN
example/src/assets/1.jpg
Normal file
BIN
example/src/assets/1.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
89
package.json
89
package.json
@ -1,65 +1,50 @@
|
||||
{
|
||||
"name": "vue-flip-down",
|
||||
"version": "1.0.7",
|
||||
"description": "vue 翻页效果的倒计时组件",
|
||||
"main": "dist/main.js",
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"version": "3.0.0",
|
||||
"scripts": {
|
||||
"dev": "webpack-dev-server --config webpack.dev.config.js",
|
||||
"build": "webpack --config webpack.production.config.js --progress --profile --colors",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build --target lib",
|
||||
"lint": "vue-cli-service lint",
|
||||
"prettier": "prettier --write \"{src,mock}/**/*.{js,css,less,vue}\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/javaLuo/vue-flip-down.git"
|
||||
},
|
||||
"keywords": [
|
||||
"vue"
|
||||
],
|
||||
"author": "L",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/javaLuo/vue-flip-down/issues"
|
||||
},
|
||||
"homepage": "https://github.com/javaLuo/vue-flip-down#readme",
|
||||
"files": ["dist"],
|
||||
"main": "./dist/vue-flip-down.umd.min.js",
|
||||
"dependencies": {
|
||||
"optimize-css-assets-webpack-plugin": "^5.0.4",
|
||||
"terser-webpack-plugin": "^4.1.0",
|
||||
"vue": "^2.6.12"
|
||||
"core-js": "^3.6.5",
|
||||
"vue": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.6",
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
||||
"@babel/plugin-transform-runtime": "^7.11.5",
|
||||
"@babel/polyfill": "^7.11.5",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"autoprefixer": "^9.8.6",
|
||||
"babel-loader": "^8.1.0",
|
||||
"babel-plugin-import": "^1.13.0",
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
||||
"babel-preset-vue-app": "^2.0.0",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"css-loader": "^4.3.0",
|
||||
"less": "^3.12.2",
|
||||
"less-loader": "^7.0.1",
|
||||
"postcss-loader": "^4.0.1",
|
||||
"style-loader": "^1.2.1",
|
||||
"url-loader": "^4.1.0",
|
||||
"vue-loader": "^15.9.3",
|
||||
"vue-template-compiler": "^2.6.12",
|
||||
"webpack": "^4.44.1",
|
||||
"webpack-cli": "^3.3.12",
|
||||
"webpack-dev-server": "^3.11.0"
|
||||
"@vue/cli-plugin-babel": "~4.5.0",
|
||||
"@vue/cli-plugin-eslint": "~4.5.0",
|
||||
"@vue/cli-service": "~4.5.0",
|
||||
"@vue/compiler-sfc": "^3.0.0",
|
||||
"@vue/eslint-config-prettier": "^6.0.0",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"eslint": "^6.7.2",
|
||||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"eslint-plugin-vue": "^7.0.0",
|
||||
"less": "^3.0.4",
|
||||
"less-loader": "^5.0.0",
|
||||
"prettier": "^2.2.1"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": false,
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"plugin:vue/vue3-essential",
|
||||
"eslint:recommended",
|
||||
"@vue/prettier"
|
||||
],
|
||||
"parserOptions": {
|
||||
"parser": "babel-eslint"
|
||||
},
|
||||
"rules": {}
|
||||
},
|
||||
"browserslist": [
|
||||
"iOS >= 8",
|
||||
"Android > 4.1",
|
||||
"last 1 versions",
|
||||
"> 1%",
|
||||
"last 2 versions",
|
||||
"not dead"
|
||||
]
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
/** postcss-loader 解析器所需的配置文件 **/
|
||||
module.exports = {
|
||||
plugins: [require("autoprefixer")()]
|
||||
};
|
BIN
public/1.gif
BIN
public/1.gif
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
BIN
public/2.gif
BIN
public/2.gif
Binary file not shown.
Before Width: | Height: | Size: 9.9 KiB |
BIN
public/demo.gif
BIN
public/demo.gif
Binary file not shown.
Before Width: | Height: | Size: 61 KiB |
270
src/app.vue
270
src/app.vue
@ -1,21 +1,30 @@
|
||||
<!-- 翻页效果 倒计时组件 -->
|
||||
<template>
|
||||
<div :class="['vue-countdown-component', { theme2: theme !== 1 }, {ie: isIE}]">
|
||||
<template v-for="(item, index) in timeArray">
|
||||
<div :class="['time-box']"
|
||||
:key="index">
|
||||
<div
|
||||
:class="['vue-countdown-component', { theme2: theme !== 1 }, { ie: isIE }]"
|
||||
>
|
||||
<template v-for="(item, index) in timeArray" :key="index">
|
||||
<div :class="['time-box']">
|
||||
<!-- 底层基础div -->
|
||||
<div class="base">{{ item }}<div class="base-b">{{ timeArrayT[index] }}</div>
|
||||
<div class="base">
|
||||
{{ item }}
|
||||
<div class="base-b">{{ timeArrayT[index] }}</div>
|
||||
</div>
|
||||
<!-- 翻页动画div -->
|
||||
<div :class="['face',{ anime: isAnimate[index] }]"
|
||||
@animationend="onAnimateEnd(index)">{{ timeArrayT[index] }}</div>
|
||||
<div :class="['back',{ anime: isAnimate[index] }]">{{ item }}</div>
|
||||
<div
|
||||
:class="['face', { anime: isAnimate[index] }]"
|
||||
@animationend="onAnimateEnd(index)"
|
||||
>
|
||||
{{ timeArrayT[index] }}
|
||||
</div>
|
||||
<div :class="['back', { anime: isAnimate[index] }]">{{ item }}</div>
|
||||
</div>
|
||||
<!-- 文字 -->
|
||||
<div class="time-unit"
|
||||
:key="`unit-${index}`"
|
||||
v-if="isTimeUnitShow(index)">
|
||||
<div
|
||||
class="time-unit"
|
||||
:key="`unit-${index}`"
|
||||
v-if="isTimeUnitShow(index)"
|
||||
>
|
||||
{{ setTimeUnit(index) }}
|
||||
</div>
|
||||
</template>
|
||||
@ -23,100 +32,104 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
isIE: false,
|
||||
timeArray:
|
||||
this.theme === 2
|
||||
? new Array(this.type * 2).fill("0")
|
||||
: new Array(this.type).fill("00"),
|
||||
timeArrayT:
|
||||
this.theme === 2
|
||||
? new Array(this.type * 2).fill("0")
|
||||
: new Array(this.type).fill("00"),
|
||||
isAnimate:
|
||||
this.theme === 2
|
||||
? new Array(this.type * 2).fill(false)
|
||||
: new Array(this.type).fill(false)
|
||||
};
|
||||
},
|
||||
emits: ["timeUp"],
|
||||
props: {
|
||||
endDate: { type: [Date, Number, String], default: 0 }, // 截止时间
|
||||
type: { type: [Number, String], default: 4 }, // 时间精度 4/3/2/1
|
||||
theme: { type: [Number, String], default: 1 },
|
||||
timeUnit: { type: Array, default: () => [] }
|
||||
timeUnit: { type: Array, default: () => [] },
|
||||
},
|
||||
computed: {
|
||||
endTime() {
|
||||
if (this.endDate instanceof Date) {
|
||||
return this.endDate.getTime();
|
||||
setup(props, context) {
|
||||
const isIE = ref(false);
|
||||
const timeArray = ref(
|
||||
props.theme === 2
|
||||
? new Array(props.type * 2).fill("0")
|
||||
: new Array(props.type).fill("00")
|
||||
);
|
||||
const timeArrayT = ref(
|
||||
props.theme === 2
|
||||
? new Array(props.type * 2).fill("0")
|
||||
: new Array(props.type).fill("00")
|
||||
);
|
||||
const isAnimate = ref(
|
||||
props.theme === 2
|
||||
? new Array(props.type * 2).fill(false)
|
||||
: new Array(props.type).fill(false)
|
||||
);
|
||||
const timer = ref(null);
|
||||
|
||||
const endTime = computed(() => {
|
||||
if (props.endDate instanceof Date) {
|
||||
return props.endDate.getTime();
|
||||
}
|
||||
return Number(this.endDate) > 0 ? Number(this.endDate) : 0;
|
||||
},
|
||||
step() {
|
||||
return this.theme === 1 ? 1 : 2;
|
||||
},
|
||||
arr() {
|
||||
const length = this.timeArray.length;
|
||||
const step = this.step;
|
||||
return Number(props.endDate) > 0 ? Number(props.endDate) : 0;
|
||||
});
|
||||
|
||||
const step = computed(() => (props.theme === 1 ? 1 : 2));
|
||||
const arr = computed(() => {
|
||||
const length = timeArray.value.length;
|
||||
const temp = [
|
||||
length - 1,
|
||||
length - step - 1,
|
||||
length - step * 2 - 1,
|
||||
length - step * 3 - 1
|
||||
length - step.value - 1,
|
||||
length - step.value * 2 - 1,
|
||||
length - step.value * 3 - 1,
|
||||
];
|
||||
temp.length = this.type > 1 ? this.type : 1;
|
||||
temp.length = props.type > 1 ? props.type : 1;
|
||||
return temp;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
timeArray(newV, oldV) {
|
||||
});
|
||||
|
||||
watch(timeArray, (newV, oldV) => {
|
||||
const diff = [];
|
||||
newV.forEach((value, index) => {
|
||||
if (value !== oldV[index]) {
|
||||
diff.push({ value, index });
|
||||
this.$set(this.isAnimate, index, true);
|
||||
isAnimate.value[index] = true;
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
diff.forEach(item => {
|
||||
this.$set(this.timeArrayT, item.index, item.value);
|
||||
diff.forEach((item) => {
|
||||
timeArrayT.value[item.index] = item.value;
|
||||
});
|
||||
}, 350);
|
||||
},
|
||||
endTime(newV) {
|
||||
if (newV > 0) {
|
||||
this.start();
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
mounted() {
|
||||
if (
|
||||
window.ActiveXObject ||
|
||||
"ActiveXObject" in window ||
|
||||
window.navigator.userAgent.indexOf("Edge") > -1
|
||||
) {
|
||||
this.isIE = true;
|
||||
}
|
||||
this.start(0);
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearTimeout(this.timer);
|
||||
},
|
||||
methods: {
|
||||
// 开始倒计时
|
||||
start(step = 1000) {
|
||||
clearTimeout(this.timer);
|
||||
this.timer = setTimeout(() => {
|
||||
let t = this.endTime - new Date().getTime(); // 剩余的毫秒数
|
||||
watch(endTime, (newV) => {
|
||||
if (newV > 0) {
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (
|
||||
window.ActiveXObject ||
|
||||
"ActiveXObject" in window ||
|
||||
window.navigator.userAgent.indexOf("Edge") > -1
|
||||
) {
|
||||
isIE.value = true;
|
||||
}
|
||||
start(0);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearTimeout(timer.value);
|
||||
});
|
||||
|
||||
/**
|
||||
* 开始倒计时
|
||||
* @param st 重复执行的间隔时间
|
||||
*/
|
||||
const start = (st = 1000) => {
|
||||
clearTimeout(timer.value);
|
||||
timer.value = setTimeout(() => {
|
||||
let t = endTime.value - new Date().getTime(); // 剩余的毫秒数
|
||||
t = t < 0 ? 0 : t;
|
||||
let day = 0; // 剩余的天
|
||||
let hour = 0; // 剩余的小时
|
||||
let min = 0; // 剩余的分钟
|
||||
let second = 0; // 剩余的秒
|
||||
const type = Number(this.type);
|
||||
const type = Number(props.type);
|
||||
if (type >= 4) {
|
||||
day = Math.floor(t / 86400000); // 剩余的天
|
||||
hour = Math.floor(t / 3600000 - day * 24); // 剩余的小时 已排除天
|
||||
@ -133,74 +146,71 @@ export default {
|
||||
second = Math.floor(t / 1000); // 剩余的秒
|
||||
}
|
||||
|
||||
let arr = [];
|
||||
if (Number(this.theme) === 1) {
|
||||
let ar = [];
|
||||
if (Number(props.theme) === 1) {
|
||||
// 不分开
|
||||
type >= 4 && arr.push(String(day).padStart(2, "0"));
|
||||
type >= 3 && arr.push(String(hour).padStart(2, "0"));
|
||||
type >= 2 && arr.push(String(min).padStart(2, "0"));
|
||||
arr.push(String(second).padStart(2, "0"));
|
||||
type >= 4 && ar.push(String(day).padStart(2, "0"));
|
||||
type >= 3 && ar.push(String(hour).padStart(2, "0"));
|
||||
type >= 2 && ar.push(String(min).padStart(2, "0"));
|
||||
ar.push(String(second).padStart(2, "0"));
|
||||
} else {
|
||||
// 分开
|
||||
type >= 4 &&
|
||||
arr.push(
|
||||
...String(day)
|
||||
.padStart(2, "0")
|
||||
.split("")
|
||||
);
|
||||
type >= 3 &&
|
||||
arr.push(
|
||||
...String(hour)
|
||||
.padStart(2, "0")
|
||||
.split("")
|
||||
);
|
||||
type >= 2 &&
|
||||
arr.push(
|
||||
...String(min)
|
||||
.padStart(2, "0")
|
||||
.split("")
|
||||
);
|
||||
arr.push(
|
||||
...String(second)
|
||||
.padStart(2, "0")
|
||||
.split("")
|
||||
);
|
||||
type >= 4 && ar.push(...String(day).padStart(2, "0").split(""));
|
||||
type >= 3 && ar.push(...String(hour).padStart(2, "0").split(""));
|
||||
type >= 2 && ar.push(...String(min).padStart(2, "0").split(""));
|
||||
ar.push(...String(second).padStart(2, "0").split(""));
|
||||
}
|
||||
this.timeArray = arr;
|
||||
timeArray.value = ar;
|
||||
|
||||
if (t > 0) {
|
||||
this.start();
|
||||
start();
|
||||
} else {
|
||||
this.$emit("timeUp");
|
||||
context.emit("timeUp");
|
||||
}
|
||||
}, step);
|
||||
},
|
||||
}, st);
|
||||
};
|
||||
|
||||
// 动画完毕后,去掉对应的class, 为下次动画做准备
|
||||
onAnimateEnd(index) {
|
||||
this.$set(this.isAnimate, index, false);
|
||||
},
|
||||
isTimeUnitShow(index) {
|
||||
if (this.arr.includes(index)) {
|
||||
if (index === this.timeArray.length - 1 && !this.timeUnit[3]) {
|
||||
const onAnimateEnd = (index) => {
|
||||
isAnimate.value[index] = false;
|
||||
};
|
||||
|
||||
const isTimeUnitShow = (index) => {
|
||||
if (arr.value.includes(index)) {
|
||||
if (index === timeArray.value.length - 1 && !props.timeUnit[3]) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
setTimeUnit(index) {
|
||||
};
|
||||
|
||||
const setTimeUnit = (index) => {
|
||||
switch (index) {
|
||||
case this.timeArray.length - 1:
|
||||
return this.timeUnit[3] || ""; // 秒
|
||||
case this.timeArray.length - this.step - 1:
|
||||
return this.timeUnit[2] || ""; // 分
|
||||
case this.timeArray.length - this.step * 2 - 1:
|
||||
return this.timeUnit[1] || ""; // 时
|
||||
case timeArray.value.length - 1:
|
||||
return props.timeUnit[3] || ""; // 秒
|
||||
case timeArray.value.length - step.value - 1:
|
||||
return props.timeUnit[2] || ""; // 分
|
||||
case timeArray.value.length - step.value * 2 - 1:
|
||||
return props.timeUnit[1] || ""; // 时
|
||||
default:
|
||||
return this.timeUnit[0] || ""; // 天
|
||||
return props.timeUnit[0] || ""; // 天
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isIE,
|
||||
timeArray,
|
||||
timeArrayT,
|
||||
isAnimate,
|
||||
endTime,
|
||||
step,
|
||||
arr,
|
||||
onAnimateEnd,
|
||||
isTimeUnitShow,
|
||||
setTimeUnit,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
import App from './app.vue';
|
||||
export default App;
|
3
src/main.js
Normal file
3
src/main.js
Normal file
@ -0,0 +1,3 @@
|
||||
import Component from "./App.vue";
|
||||
|
||||
export default Component;
|
12
vue.config.js
Normal file
12
vue.config.js
Normal file
@ -0,0 +1,12 @@
|
||||
const path = require("path");
|
||||
|
||||
module.exports = {
|
||||
css: {
|
||||
extract: process.env.NODE_ENV === "production" ? false : true,
|
||||
},
|
||||
outputDir: process.env.NODE_ENV === "production" ? path.resolve(__dirname, "dist") : path.resolve(__dirname, "example-dist"),
|
||||
// publicPath: process.env.NODE_ENV === "production" ? "/" : "/example/",
|
||||
// configureWebpack: config => {
|
||||
// return {};
|
||||
// },
|
||||
};
|
@ -1,40 +0,0 @@
|
||||
var path = require("path");
|
||||
const VueLoaderPlugin = require("vue-loader/lib/plugin");
|
||||
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
entry: path.join(__dirname, "example", "main.js"),
|
||||
output: {
|
||||
filename: "bundle.js",
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /.vue$/,
|
||||
use: ["vue-loader"],
|
||||
// include: [path.join(__dirname, "example")],
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
use: ["babel-loader"],
|
||||
// include: [path.join(__dirname, "example")],
|
||||
},
|
||||
{
|
||||
// .css 解析
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader", "postcss-loader"],
|
||||
// include: path.resolve(__dirname, "src"),
|
||||
},
|
||||
{
|
||||
// .less 解析
|
||||
test: /\.less$/,
|
||||
use: ["style-loader", "css-loader", "postcss-loader", "less-loader"],
|
||||
// include: path.resolve(__dirname, "src"),
|
||||
},
|
||||
],
|
||||
},
|
||||
devServer: {
|
||||
contentBase: path.join(__dirname, "example"),
|
||||
},
|
||||
plugins: [new VueLoaderPlugin()],
|
||||
};
|
@ -1,89 +0,0 @@
|
||||
/** 这是用于开发环境的webpack配置文件 **/
|
||||
|
||||
const path = require("path"); // 获取绝对路径用
|
||||
const webpack = require("webpack"); // webpack核心
|
||||
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); // 每次打包前清除旧的build文件夹
|
||||
const VueLoaderPlugin = require("vue-loader/lib/plugin");
|
||||
const TerserPlugin = require("terser-webpack-plugin"); // 优化js
|
||||
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); // 压缩CSS
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
entry: [
|
||||
"./src/index.js", // 项目入口
|
||||
],
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"), // 将打包好的文件放在此路径下,dev模式中,只会在内存中存在,不会真正的打包到此路径
|
||||
filename: "[name].js", //编译后的文件名字
|
||||
library: ["vue-flip-down"],
|
||||
libraryTarget: "umd",
|
||||
globalObject: 'this'
|
||||
},
|
||||
externals: {
|
||||
vue: "vue",
|
||||
},
|
||||
optimization: {
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
parallel: true, // 多线程并行构建
|
||||
terserOptions: {
|
||||
// https://github.com/terser/terser#minify-options
|
||||
compress: {
|
||||
warnings: false, // 删除无用代码时是否给出警告
|
||||
drop_console: true, // 删除所有的console.*
|
||||
drop_debugger: true, // 删除所有的debugger
|
||||
},
|
||||
},
|
||||
}),
|
||||
new OptimizeCSSAssetsPlugin({}),
|
||||
],
|
||||
splitChunks: {
|
||||
chunks: "all",
|
||||
},
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: ["vue-loader"],
|
||||
include: path.resolve(__dirname, "src"),
|
||||
},
|
||||
{
|
||||
// .js .jsx用babel解析
|
||||
test: /\.js?$/,
|
||||
use: ["babel-loader"],
|
||||
include: path.resolve(__dirname, "src"),
|
||||
},
|
||||
{
|
||||
// .css 解析
|
||||
test: /\.css$/,
|
||||
use: ["style-loader", "css-loader", "postcss-loader"],
|
||||
include: path.resolve(__dirname, "src"),
|
||||
},
|
||||
{
|
||||
// .less 解析
|
||||
test: /\.less$/,
|
||||
use: ["style-loader", "css-loader", "postcss-loader", "less-loader"],
|
||||
include: path.resolve(__dirname, "src"),
|
||||
},
|
||||
{
|
||||
// 文件解析
|
||||
test: /\.(eot|woff|otf|svg|ttf|woff2|appcache|mp3|mp4|pdf)(\?|$)/,
|
||||
include: path.resolve(__dirname, "src"),
|
||||
use: ["file-loader?name=assets/[name].[ext]"],
|
||||
},
|
||||
{
|
||||
// 图片解析
|
||||
test: /\.(png|jpg|gif)(\?|$)/,
|
||||
include: path.resolve(__dirname, "src"),
|
||||
use: ["url-loader?limit=8192&name=assets/[name].[ext]"],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [new VueLoaderPlugin(), new CleanWebpackPlugin()],
|
||||
resolve: {
|
||||
extensions: [".js", ".vue", ".less", ".css"], //后缀名自动补全
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user