From 7b1b667792b59dbe4645a2ff54a1825f91111af3 Mon Sep 17 00:00:00 2001
From: 07akioni <07akioni2@gmail.com>
Date: Sun, 16 Feb 2020 21:52:38 +0800
Subject: [PATCH] feat(upload): wip
---
.gitignore | 1 +
.../components/upload/zhCN/basic.md | 4 +-
package.json | 5 +-
playground/uploadServer.js | 15 ++
src/Progress/src/main.vue | 23 ++-
src/Upload/src/Upload.vue | 148 ++++++++++++++++--
src/Upload/src/UploadProgress.vue | 61 ++++++++
.../FadeInHeightExpandTransition.vue | 7 +-
styles/Upload.scss | 65 ++++++++
styles/themes/dark/components/Upload.scss | 5 +
styles/themes/dark/index.scss | 2 +
styles/themes/light/components/Progress.scss | 2 +-
styles/themes/light/components/Upload.scss | 5 +
styles/themes/light/index.scss | 2 +
styles/themes/transition.scss | 10 +-
15 files changed, 327 insertions(+), 28 deletions(-)
create mode 100644 playground/uploadServer.js
create mode 100644 src/Upload/src/UploadProgress.vue
create mode 100644 styles/themes/dark/components/Upload.scss
create mode 100644 styles/themes/light/components/Upload.scss
diff --git a/.gitignore b/.gitignore
index eaf2234c1..6c531e03b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ test-size
test-bundle
test/unit/coverage
package-lock.json
+playground/temp
yarn.lock
lib
es
diff --git a/demo/documentation/components/upload/zhCN/basic.md b/demo/documentation/components/upload/zhCN/basic.md
index 5cd4a7da1..ab32406e1 100644
--- a/demo/documentation/components/upload/zhCN/basic.md
+++ b/demo/documentation/components/upload/zhCN/basic.md
@@ -1,4 +1,6 @@
# 基础用法
```html
-
+
+ 上传文件
+
```
\ No newline at end of file
diff --git a/package.json b/package.json
index b8be53d65..b71b1d86f 100644
--- a/package.json
+++ b/package.json
@@ -59,6 +59,7 @@
"babel-preset-env": "^1.7.0",
"chai": "^4.2.0",
"copy-webpack-plugin": "^5.1.1",
+ "cors": "^2.8.5",
"cross-env": "^5.2.1",
"css-loader": "^2.1.1",
"cssnano": "^4.1.10",
@@ -66,6 +67,7 @@
"emoji-unicode": "^1.1.0",
"eslint": "^6.8.0",
"eslint-plugin-vue": "^5.0.0",
+ "express": "^4.17.1",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"file-loader": "^3.0.1",
"glob": "^7.1.6",
@@ -84,9 +86,9 @@
"marked": "^0.7.0",
"memory-fs": "^0.4.1",
"mocha": "^6.2.2",
+ "multer": "^1.4.2",
"ncp": "^2.0.0",
"node-sass": "^4.13.1",
- "sass-loader": "^7.3.1",
"postcss": "^7.0.26",
"postcss-cli": "^6.1.3",
"postcss-loader": "^3.0.0",
@@ -96,6 +98,7 @@
"rollup": "^1.31.0",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-vue": "^5.1.6",
+ "sass-loader": "^7.3.1",
"schema-utils": "^1.0.0",
"sinon": "^7.5.0",
"style-loader": "^0.23.1",
diff --git a/playground/uploadServer.js b/playground/uploadServer.js
new file mode 100644
index 000000000..e6d98f867
--- /dev/null
+++ b/playground/uploadServer.js
@@ -0,0 +1,15 @@
+const express = require('express')
+const multer = require('multer')
+const cors = require('cors')
+const path = require('path')
+
+const app = express()
+const upload = multer({ dest: path.resolve(__dirname, 'temp') })
+
+app.options('/upload-test', cors())
+app.post('/upload-test', cors(), upload.any(), function (req, res, next) {
+ console.log(req.files)
+ res.send('very good')
+})
+
+app.listen(3000)
diff --git a/src/Progress/src/main.vue b/src/Progress/src/main.vue
index 896e67d43..a7c2658d4 100644
--- a/src/Progress/src/main.vue
+++ b/src/Progress/src/main.vue
@@ -90,7 +90,9 @@
-
-
- {{ file.name }}
-
+
+
+
+
+
+
+
+
+ {{ file.name }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/_transition/FadeInHeightExpandTransition.vue b/src/_transition/FadeInHeightExpandTransition.vue
index 02ae2a495..25fdc3c4f 100644
--- a/src/_transition/FadeInHeightExpandTransition.vue
+++ b/src/_transition/FadeInHeightExpandTransition.vue
@@ -8,6 +8,10 @@ export default {
width: {
type: Boolean,
default: false
+ },
+ appear: {
+ type: Boolean,
+ default: false
}
},
beforeDestroy () {
@@ -78,7 +82,8 @@ export default {
render (h) {
return h('transition', {
props: {
- name: this.width ? 'n-fade-in-width-expand-transition' : 'n-fade-in-height-expand-transition'
+ name: this.width ? 'n-fade-in-width-expand-transition' : 'n-fade-in-height-expand-transition',
+ appear: this.appear
},
on: {
beforeLeave: this.handleBeforeLeave,
diff --git a/styles/Upload.scss b/styles/Upload.scss
index 009ccfff5..b55a5ffe9 100644
--- a/styles/Upload.scss
+++ b/styles/Upload.scss
@@ -7,5 +7,70 @@
height: 0;
opacity: 0;
}
+ @include e(activator) {
+ display: inline-block;
+ }
+ @include b(upload-file-list) {
+ margin-top: 8px;
+ line-height: 1.5;
+ @include b(upload-file) {
+ cursor: pointer;
+ padding: 6px 12px 0 12px;
+ transition: background-color .3s $--n-ease-in-out-cubic-bezier;
+ border-radius: 6px;
+ &:hover {
+ background-color: map-get($--upload-file-item-background-color, 'hover');
+ @include b(upload-file-info) {
+ @include e(action) {
+ opacity: 1;
+ }
+ }
+ }
+ @include m(error-status) {
+ @include b(upload-file-info) {
+ @include e(name) {
+ color: $--error-6;
+ }
+ }
+ }
+ @include m(success-status) {
+ @include b(upload-file-info) {
+ @include e(name) {
+ color: $--success-6;
+ }
+ }
+ }
+ @include b(upload-file-info) {
+ position: relative;
+ padding-bottom: 6px;
+ @include e(name) {
+ font-size: 14px;
+ color: $--n-secondary-text-color;
+ transition: color .3s $--n-ease-in-out-cubic-bezier;
+ }
+ @include e(action) {
+ padding-bottom: inherit;
+ position: absolute;
+ right: 0;
+ top: 0;
+ bottom: 0;
+ width: 80px;
+ display: flex;
+ align-items: center;
+ transition: opacity .2s $--n-ease-in-out-cubic-bezier;
+ flex-direction: row-reverse;
+ @include b(button) {
+ &:not(:first-child) {
+ margin-right: 8px;
+ }
+ }
+ }
+ }
+ @include b(progress) {
+ @include fade-in-height-expand-transition;
+ margin-bottom: 6px;
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/styles/themes/dark/components/Upload.scss b/styles/themes/dark/components/Upload.scss
new file mode 100644
index 000000000..30e334740
--- /dev/null
+++ b/styles/themes/dark/components/Upload.scss
@@ -0,0 +1,5 @@
+@mixin setup-dark-upload {
+ $--uploadd-file-item-background-color: (
+ 'hover': change-color($--primary-6, $alpha: .15)
+ ) !global;
+}
\ No newline at end of file
diff --git a/styles/themes/dark/index.scss b/styles/themes/dark/index.scss
index 64dd2fd15..b0010b85a 100644
--- a/styles/themes/dark/index.scss
+++ b/styles/themes/dark/index.scss
@@ -55,6 +55,7 @@
@import 'components/Result.scss';
@import 'components/Tree.scss';
@import 'components/Typography.scss';
+@import 'components/Upload.scss';
@mixin setup-dark-theme($in-js-env: false) {
@include setup-dark-colors();
@@ -142,5 +143,6 @@
@include setup-dark-result;
@include setup-dark-tree;
@include setup-dark-typography;
+ @include setup-dark-upload;
}
}
diff --git a/styles/themes/light/components/Progress.scss b/styles/themes/light/components/Progress.scss
index 0aa15ff82..fe770f15a 100644
--- a/styles/themes/light/components/Progress.scss
+++ b/styles/themes/light/components/Progress.scss
@@ -1,5 +1,5 @@
@mixin setup-light-progress {
- $--progress-rail-color: rgba(0, 0, 0, .1) !global;
+ $--progress-rail-color: $--n-action-panel-color !global;
$--progress-fill-color: (
'default': $--info-6,
'info': $--info-6,
diff --git a/styles/themes/light/components/Upload.scss b/styles/themes/light/components/Upload.scss
new file mode 100644
index 000000000..54438e48d
--- /dev/null
+++ b/styles/themes/light/components/Upload.scss
@@ -0,0 +1,5 @@
+@mixin setup-light-upload {
+ $--upload-file-item-background-color: (
+ 'hover': change-color($--primary-6, $alpha: .1)
+ ) !global;
+}
\ No newline at end of file
diff --git a/styles/themes/light/index.scss b/styles/themes/light/index.scss
index 7d56c4168..f76b2a8f6 100644
--- a/styles/themes/light/index.scss
+++ b/styles/themes/light/index.scss
@@ -55,6 +55,7 @@
@import 'components/Result.scss';
@import 'components/Tree.scss';
@import 'components/Typography.scss';
+@import 'components/Upload.scss';
@mixin setup-light-theme($in-js-env: false) {
@include setup-light-colors();
@@ -141,5 +142,6 @@
@include setup-light-result;
@include setup-light-tree;
@include setup-light-typography;
+ @include setup-light-upload;
}
}
diff --git a/styles/themes/transition.scss b/styles/themes/transition.scss
index 1f4db3244..7ecae7ccf 100644
--- a/styles/themes/transition.scss
+++ b/styles/themes/transition.scss
@@ -135,7 +135,7 @@
}
}
-@mixin fade-in-height-expand-transition ($name: 'fade-in-height-expand', $duration: .3s, $delay: 0s, $original-transition: ()) {
+@mixin fade-in-height-expand-transition ($name: 'fade-in-height-expand', $duration: .3s, $original-transition: (), $leave-delay: 0s) {
&.#{$namespace}-#{$name}-transition-leave, &.#{$namespace}-#{$name}-transition-enter-to {
opacity: 1;
}
@@ -147,10 +147,10 @@
&.#{$namespace}-#{$name}-transition-leave-active {
overflow: hidden;
transition:
- max-height $duration $--n-ease-in-out-cubic-bezier,
- opacity $duration $--n-ease-out-cubic-bezier,
- margin-top $duration $--n-ease-in-out-cubic-bezier,
- margin-bottom $duration $--n-ease-in-out-cubic-bezier,
+ max-height $duration $--n-ease-in-out-cubic-bezier $leave-delay,
+ opacity $duration $--n-ease-out-cubic-bezier $leave-delay,
+ margin-top $duration $--n-ease-in-out-cubic-bezier $leave-delay,
+ margin-bottom $duration $--n-ease-in-out-cubic-bezier $leave-delay,
$original-transition;
}
&.#{$namespace}-#{$name}-transition-enter-active {