Browse Source

fix: radio 代码优化

lilinsen 5 years ago
parent
commit
49e789d0a6

+ 31 - 0
src/packages/radio/demo.vue

@@ -130,6 +130,35 @@
         </span>
       </nut-cell>
     </div>    
+    <h4>标签样式</h4>
+    <nut-cell>
+        <span slot="title">
+          <nut-radio 
+          :type="'list'"           
+          :name="demo6name" 
+          :value="1"
+          :checked="false"
+          >
+          备选项1
+          </nut-radio>
+          <nut-radio 
+          :type="'list'"           
+          :name="demo6name" 
+          :value="2"
+          :checked="false"
+          >
+          备选项2
+          </nut-radio>
+          <nut-radio 
+          :type="'list'"           
+          :name="demo6name" 
+          :value="3"
+          :checked="false"
+          >
+          备选项3
+          </nut-radio>
+        </span>
+      </nut-cell>
   </div>
 </template>
 
@@ -143,6 +172,8 @@ export default {
       radioVal3: 'b',
       radioVal4: 'b',
       radioVal5: 'a',
+      demo6value:1,
+      demo6name:'test',
       radioGroupVal1: 'b',
       radioGroupVal2: '2',
       radioGroupVal3: '2',

+ 53 - 1
src/packages/radio/radio.scss

@@ -1,5 +1,7 @@
 @import '../../styles/animation/pulse';
-
+.warper{
+	display: inline-block;
+}
 .nut-radio {
 	margin-right: 10px;
 
@@ -92,3 +94,53 @@
 		}
 	}
 }
+.nut-radio-list{
+	display: inline-block;
+	text-align: center;
+	line-height: 28px;
+	height: 28px;	
+	position: relative;
+	font-size: 14px;
+	label{
+		display: inline-block;		
+		padding:0 15px;
+	}
+	input{
+		position: absolute;
+		opacity: 0;
+		z-index: 3;
+		top: 0;
+		left: 0;
+		width: 100%;
+		height: 100%;
+		display: block;
+		margin: 0;
+		padding:0;
+	}
+	.text-box{
+		position: relative;
+		z-index: 2;
+		color:#969696;
+	}
+	.box-border{
+		top:0;
+		left: 0;
+		position: absolute;
+		width: 100%;
+		height: 100%;
+		z-index: 1;
+		border-radius: 14px;	
+		background: rgba(255,255,255,1);
+		border: 1px solid rgba(230,230,230,1);
+	}
+	input:checked + .text-box{
+		color: #E1251B;
+		position: relative;
+		z-index: 2;
+	}
+	input:checked +.text-box + .box-border{
+		background: rgba(255,239,235,1);
+		border: 1px solid rgba(225,37,27,1);
+	}
+	
+}

+ 23 - 3
src/packages/radio/radio.vue

@@ -5,7 +5,7 @@
       type="radio"
       :value="currentValue"
       :class="{ 'nut-radio-ani': isAnimated }"
-      :checked="currentValue === label"
+      :checked="checked"
       :disabled="isDisabled"
       :label="label"
     />
@@ -13,8 +13,21 @@
       <slot></slot>
     </span>
   </label>
-  <div v-if="type === 'list'" class="list-box">
-
+  <div v-if="type === 'list'" class="nut-radio-list">
+      <label for="">
+          
+          <input
+            type="radio"
+            :value="currentValue"
+            :class="{ 'nut-radio-ani': isAnimated }"
+            :checked="checked"
+            :disabled="isDisabled"
+            :label="label"
+            :name="name"
+          />
+          <div class="text-box"><slot></slot></div>
+          <div class="box-border"></div>
+      </label>
   </div>
 </div>
   
@@ -30,6 +43,10 @@ export default {
       type: [String, Number, Boolean],
       default: false
     },
+    checked:{
+      type:Boolean,
+      default:false
+    },
     label: [String, Number, Boolean],
     size: {
       type: String,
@@ -46,6 +63,9 @@ export default {
     type:{
       type: String,
       default:'radio'
+    },
+    name:{
+      type:String
     }
   },
   data() {

+ 1 - 0
src/packages/uploader/demo.vue

@@ -232,6 +232,7 @@ export default {
 .img-list{
   display: flex;  
   align-items: center;
+  flex-wrap: wrap;
 }
 
 .demo-1{

+ 84 - 23
src/packages/uploader/doc.md

@@ -2,27 +2,41 @@
 
 文件上传组件
 
-## 基本用法
+## 通用方法
+
+模版部分如下:要说的一点就是 `img-cell` 是为了 `demo` 展示而临时写的一个模块,所以不能直接使用,需要使用
+下面的模版。
 
 ```html
-<nut-uploader
-    name="uploader-demo"
-    :url="url"
-    :isPreview="true"
-    :acceptType = "['image/jpeg', 'image/png', 'image/gif', 'image/bmp']"
-    @start="onStart"
-    @success="onSuccess"
-    @fail="onFail"
-    @progress="onProgress"
-    @preview="onPreview"
-    @showMsg="showMsgFn"
-    typeError="对不起,不支持上传该类型文件!"
-    limitError="对不起,文件大小超过限制!"
->
-上传
-</nut-uploader>   
+<div class="preview-img-box">
+  <transition name="fade">
+      <div class="img-list" v-if="previewImg">
+        <img-cell v-for="(item,index) in previewImg" 
+                  :key="index"   
+                  :src="item"
+                  :clear="()=>{clearImg(index)}"
+                    /> 
+      </div>
+  </transition>
+  <nut-uploader
+        class="demo-1"
+        :name="name"
+        :url="url"
+        :xhrState="stateNum"
+        :acceptType="['image/jpeg', 'image/png', 'image/gif', 'image/bmp']"
+        :isPreview="true"
+        @preview="preview"
+        @success="onSuccess"
+        @failure="onFail"
+        @start="onStart"
+        @showMsg="showMsgFn"
+        :multiple="true"
+  >+</nut-uploader> 
+</div>
 ```
 
+主要使用了 `@preview` 、 `@success` 、`@failure`、 ` @start`、 `@showMsg` 5个 事件监听上传的整个过程,代码部分如下:
+
 ```javascript
 export default { 
   data() {
@@ -39,11 +53,8 @@ export default {
       },
       onFail(file,res){
         alert('上传失败!');
-      },
-      onProgress(file, loaded, total) {
-        console.log('上传进度:'+parseInt((100 * loaded) / total)+'%');
-      },
-      onPreview(file) {
+      },     
+      preview(file) {
         this.previewImg = file;
       },
       showMsgFn(msg){
@@ -52,7 +63,57 @@ export default {
   }
 ```
 
-## 高级用法
+img-cell 模版代码如下:
+
+```html
+<template>
+    <div class="img-outbox">  
+        <i class="close" @click="close"></i>      
+        <img class="img-box" v-if="src" :src="src" alt />        
+    </div>
+</template>
+<script>
+export default {
+    name:"img-cell",
+    props:['src','clear'],
+    methods:{
+        close(){
+            if(Object.prototype.toString.apply(this.clear) === '[object Function]'){
+                this.clear()
+            }            
+        }
+    }
+}
+</script>
+<style lang="scss" scoped>
+    .img-outbox{
+        width: 76px;
+        height: 76px;
+        border-radius: 3px;
+        position: relative;
+        display: inline-flex;
+        align-items: center;
+        margin-right: 14px;
+        .close{
+            position: absolute;
+            display: block;
+            background: url(./../../assets/img/img-clear.png) no-repeat;
+            background-size: cover;;
+            width: 18px;
+            height: 18px;       
+            top:-9px;
+            right:-9px;    
+            cursor: pointer;
+        }
+        .img-box{
+            width: 100%;
+        }
+    }
+</style>
+```
+
+
+## 其它用法
 
 与吐司 **Toast** 组件结合使用
 

+ 1 - 1
src/packages/uploader/img-cell.vue

@@ -25,7 +25,7 @@ export default {
         position: relative;
         display: inline-flex;
         align-items: center;
-        margin-right: 14px;
+        margin-right: 12px;        
         .close{
             position: absolute;
             display: block;