Browse Source

feat: backtop taro

suzigang 4 years ago
parent
commit
0251a589e4

+ 44 - 8
src/packages/__VUE/checkbox/demo.vue

@@ -14,7 +14,10 @@
           >复选框</nut-checkbox
         >
       </nut-cell>
-      <nut-cell title="当前选中值" :desc="checkbox1" />
+      <nut-cell>
+        <div style="marginright: 10px">当前选中值</div>
+        <div>{{ checkbox1 }}</div>
+      </nut-cell>
     </nut-cell-group>
 
     <nut-cell-group title="禁用状态">
@@ -57,20 +60,43 @@
     <nut-cell-group title="checkboxGroup使用">
       <nut-cell>
         <nut-checkboxgroup v-model="checkboxgroup1">
-          <nut-checkbox v-model="checkbox9" label="1">组合复选框</nut-checkbox>
+          <nut-checkbox
+            v-model="checkbox9"
+            label="1"
+            style="margin: 2px 20px 15px 0"
+            >组合复选框</nut-checkbox
+          >
           <nut-checkbox v-model="checkbox10" label="2">组合复选框</nut-checkbox>
-          <nut-checkbox v-model="checkbox11" label="3">组合复选框</nut-checkbox>
+          <nut-checkbox
+            v-model="checkbox11"
+            label="3"
+            style="margin: 2px 20px 0 0"
+            >组合复选框</nut-checkbox
+          >
           <nut-checkbox v-model="checkbox12" label="4">组合复选框</nut-checkbox>
         </nut-checkboxgroup>
       </nut-cell>
-      <nut-cell title="当前选中值" :desc="checkboxgroup1" />
+      <nut-cell>
+        <div style="marginright: 10px">当前选中值</div>
+        <div>{{ checkboxgroup1 }}</div>
+      </nut-cell>
     </nut-cell-group>
     <nut-cell-group title="checkboxGroup禁用">
       <nut-cell>
         <nut-checkboxgroup v-model="checkboxgroup1" disabled>
-          <nut-checkbox v-model="checkbox9" label="1">组合复选框</nut-checkbox>
+          <nut-checkbox
+            v-model="checkbox9"
+            label="1"
+            style="margin: 2px 20px 15px 0"
+            >组合复选框</nut-checkbox
+          >
           <nut-checkbox v-model="checkbox10" label="2">组合复选框</nut-checkbox>
-          <nut-checkbox v-model="checkbox11" label="3">组合复选框</nut-checkbox>
+          <nut-checkbox
+            v-model="checkbox11"
+            label="3"
+            style="margin: 2px 20px 0 0"
+            >组合复选框</nut-checkbox
+          >
           <nut-checkbox v-model="checkbox12" label="4">组合复选框</nut-checkbox>
         </nut-checkboxgroup>
       </nut-cell>
@@ -82,12 +108,22 @@
           ref="group"
           @change="changeBox4"
         >
-          <nut-checkbox v-model="checkbox15" label="1">组合复选框</nut-checkbox>
+          <nut-checkbox
+            v-model="checkbox15"
+            label="1"
+            style="margin: 0 20px 0 0"
+            >组合复选框</nut-checkbox
+          >
           <nut-checkbox v-model="checkbox16" label="2">组合复选框</nut-checkbox>
         </nut-checkboxgroup>
       </nut-cell>
       <nut-cell>
-        <nut-button type="primary" @click="toggleAll(true)">全选</nut-button>
+        <nut-button
+          type="primary"
+          @click="toggleAll(true)"
+          style="margin: 0 20px 0 0"
+          >全选</nut-button
+        >
         <nut-button type="info" @click="toggleAll(false)">取消</nut-button>
       </nut-cell>
     </nut-cell-group>

+ 0 - 1
src/packages/__VUE/drag/demo.vue

@@ -31,7 +31,6 @@
 </template>
 
 <script lang="ts">
-import { ref, reactive, toRefs, watch } from 'vue';
 import { createComponent } from '../../utils/create';
 const { createDemo } = createComponent('drag');
 export default createDemo({

+ 16 - 34
src/packages/__VUE/drag/doc.taro.md

@@ -1,51 +1,33 @@
 # Drag 拖拽
 实现可拖拽的任意元素
 
-## 基本用法
+## 限制拖拽边界
 ```html
-<nut-drag>
-  <div class="touch-dom">可点击,可拖拽</div>
+<nut-drag style="width: 90%; height: 200px; border: 1px solid red" direction="all" width="120"height="40">
+    <nut-button style="width: 120px; height: 40px" type="primary">触摸移动</nut-button>
 </nut-drag>
 ```
+
 ## 限制拖拽方向
 ```html
-<nut-drag direction="x">
-  <div class="touch-dom">只能在X轴拖动</div>
-</nut-drag>
-```
-## 自动吸边
-```html
-<nut-drag direction="x" :attract="true">
-  <div class="touch-dom">拖动我</div>
-</nut-drag>
+ <nut-drag direction="x" width="120" height="40">
+      <nut-button style="width: 120px; height: 40px" type="primary">只能X轴拖拽</nut-button>
+ </nut-drag>
+ <nut-drag direction="y" width="120" height="40">
+    <nut-button style="width: 120px; height: 40px" type="primary">只能X轴拖拽</nut-button>
+ </nut-drag>
 ```
-## 限制拖拽边界
+## 不限制边界
 ```html
-<nut-drag
-  :boundary="{ top: 401, left: 9, bottom: bottom(), right: right() }"
-  :attract="true"
->
-  <div class="touch-dom">拖动我</div>
-</nut-drag>
-<script>
- setup() {
-    function right() {
-      return document.documentElement.clientWidth - 300 - 9;
-    }
-    function bottom() {
-      return document.documentElement.clientHeight - 559;
-    }
-    return {
-      right,
-      bottom
-    };
-  }
-</script>
+ <nut-drag direction="all" width="120" height="40">
+    <nut-button style="width: 120px; height: 40px" type="primary" >触摸移动</nut-button>
+ </nut-drag>
 ```
 ## Prop
 
 | 字段      | 说明                                              | 类型           | 默认值                              |
 | :-------- | :------------------------------------------------ | :------------- | :---------------------------------- |
-| attract   | 是否开启自动吸边                                  | Boolean        | false                                |
+| width   | 子元素宽度                                  | string        |              ''                   |
+| height   | 子元素高度                                  | string        |             ''                    |
 | direction | 拖拽元素的拖拽方向限制,**x**/**y**/**all**三选一 | String         | 'all'                               |
 | boundary  | 拖拽元素的拖拽边界                                | Object         | {top: 0,left: 0,right: 0,bottom: 0} |

+ 25 - 185
src/packages/__VUE/drag/index.taro.vue

@@ -1,210 +1,50 @@
 <template>
-  <view
-    :class="classes"
-    ref="myDrag"
-    @touchstart="touchStart($event)"
-    @touchmove="touchMove($event)"
-    @touchend="touchEnd($event)"
-  >
-    <slot></slot>
-  </view>
+  <movable-area>
+    <movable-view
+      :style="{ width: width + 'px', height: height + 'px' }"
+      :direction="direction"
+    >
+      <slot></slot>
+    </movable-view>
+  </movable-area>
 </template>
-
 <script lang="ts">
-import {
-  onMounted,
-  onDeactivated,
-  onActivated,
-  reactive,
-  ref,
-  computed
-} from 'vue';
+import { ref, computed, watch, onMounted } from 'vue';
 import { createComponent } from '../../utils/create';
 import requestAniFrame from '../../utils/raf';
 const { componentName, create } = createComponent('drag');
 export default create({
   props: {
-    attract: {
-      type: Boolean,
-      default: false
-    },
     direction: {
       type: String,
       default: 'all'
     },
-    boundary: {
-      type: Object,
-      default: () => {
-        return {
-          top: 0,
-          left: 0,
-          right: 0,
-          bottom: 0
-        };
-      }
+    width: {
+      type: String,
+      default: ''
+    },
+    height: {
+      type: String,
+      default: ''
     }
   },
-  setup(props, { emit }) {
-    const myDrag = ref();
-    const state = reactive({
-      keepAlive: false,
-      elWidth: 0,
-      elHeight: 0,
-      screenWidth: 0,
-      screenHeight: 0,
-      startTop: 0,
-      startLeft: 0,
-      nx: 0,
-      ny: 0,
-      xPum: 0,
-      yPum: 0,
-      position: { x: 0, y: 0 },
-      boundary: {
-        top: 0,
-        left: 0,
-        right: 0,
-        bottom: 0
-      } as Record<string, any>
-    });
-
-    const classes = computed(() => {
-      const prefixCls = componentName;
-      return {
-        [prefixCls]: true
-      };
-    });
 
-    function getInfo() {
-      const domElem = document.documentElement;
-      state.elWidth = myDrag.value.offsetWidth;
-      state.elHeight = myDrag.value.offsetHeight;
-      state.screenWidth = domElem.clientWidth;
-      state.screenHeight = domElem.clientHeight;
-    }
+  setup(props, { emit }) {
+    const direction = ref('all');
 
-    function goLeft(target: HTMLElement) {
-      if (state.boundary.left) {
-        if (+target.style.left.split('px')[0] > state.boundary.left) {
-          target.style.left = +target.style.left.split('px')[0] - 10 + 'px';
-          requestAniFrame(() => {
-            goLeft(target);
-          });
-        } else {
-          target.style.left = `${state.boundary.left}px`;
-        }
-      } else {
-        if (+target.style.left.split('px')[0] > 10) {
-          target.style.left = +target.style.left.split('px')[0] - 10 + 'px';
-          requestAniFrame(() => {
-            goLeft(target);
-          });
-        } else {
-          target.style.left = '0px';
-        }
+    function checkDirection() {
+      if (props.direction == 'x') {
+        direction.value = 'horizontal';
       }
-    }
-    function goRight(target: HTMLElement, rightLocation: number) {
-      if (rightLocation - parseInt(target.style.left.split('px')[0]) > 10) {
-        target.style.left =
-          parseInt(target.style.left.split('px')[0]) + 10 + 'px';
-        requestAniFrame(() => {
-          goRight(target, rightLocation);
-        });
-      } else {
-        target.style.left = rightLocation + 'px';
-      }
-    }
-    function touchMove(e: TouchEvent) {
-      e.preventDefault();
-      const target = e.currentTarget as HTMLElement;
-      if (e.targetTouches.length === 1) {
-        const touch = e.targetTouches[0];
-        state.nx = touch.clientX - state.position.x;
-        state.ny = touch.clientY - state.position.y;
-        state.xPum = state.startLeft + state.nx;
-        state.yPum = state.startTop + state.ny;
-        const rightLocation =
-          state.screenWidth - state.elWidth - state.boundary.right;
-        if (Math.abs(state.xPum) > rightLocation) {
-          state.xPum = rightLocation;
-        } else if (state.xPum <= state.boundary.left) {
-          state.xPum = state.boundary.left;
-        }
-        if (state.yPum < state.boundary.top) {
-          state.yPum = state.boundary.top;
-        } else if (
-          state.yPum >
-          state.screenHeight - state.elHeight - state.boundary.bottom
-        ) {
-          state.yPum =
-            state.screenHeight - state.elHeight - state.boundary.bottom;
-        }
-        if (props.direction != 'y') {
-          target.style.left = state.xPum + 'px';
-        }
-        if (props.direction != 'x') {
-          target.style.top = state.yPum + 'px';
-        }
+      if (props.direction == 'y') {
+        direction.value = 'vertical';
       }
     }
-    function touchEnd(e: TouchEvent) {
-      const target = e.currentTarget as HTMLElement;
-      const touch = e.changedTouches[0];
-      let currX = touch.clientX;
-      const rightLocation =
-        state.screenWidth - state.elWidth - state.boundary.right;
-      if (currX > rightLocation) {
-        currX = rightLocation;
-      } else if (currX < state.boundary.left) {
-        currX = state.boundary.left;
-      } else {
-        currX =
-          currX < state.screenWidth / 2 ? state.boundary.left : rightLocation;
-      }
-      if (props.direction != 'y' && props.attract) {
-        if (currX < state.screenWidth / 2) {
-          requestAniFrame(() => {
-            goLeft(target);
-          });
-        } else {
-          requestAniFrame(() => {
-            goRight(target, rightLocation);
-          });
-        }
-      }
-      if (props.direction !== 'x') {
-        target.style.top = state.yPum + 'px';
-      }
-    }
-    function touchStart(e: TouchEvent) {
-      const target = e.currentTarget as HTMLElement;
-      const touches = e.touches[0];
-      state.startTop = target.offsetTop;
-      state.startLeft = target.offsetLeft;
-      state.position.x = touches.clientX;
-      state.position.y = touches.clientY;
-    }
     onMounted(() => {
-      getInfo();
-      state.boundary = props.boundary;
-    });
-    onActivated(() => {
-      if (state.keepAlive) {
-        state.keepAlive = false;
-      }
-    });
-    onDeactivated(() => {
-      state.keepAlive = true;
-      (myDrag as any).removeEventListener('touchstart', touchStart);
-      (myDrag as any).removeEventListener('touchmove', touchMove);
-      (myDrag as any).removeEventListener('touchend', touchEnd);
+      checkDirection();
     });
     return {
-      classes,
-      myDrag,
-      touchStart,
-      touchMove,
-      touchEnd
+      direction
     };
   }
 });

+ 28 - 10
src/sites/doc/views/Main.vue

@@ -103,8 +103,13 @@
             @click="onRight"
           ></div>
         </div>
-        <ul class="doc-content-cases-content__list">
-          <li v-for="img in casesImages">
+        <ul
+          :class="[
+            'doc-content-cases-content__list',
+            themeNameValue() == 'black' ? 'noShadow' : ''
+          ]"
+        >
+          <li v-for="(img, index) in casesImages" :key="index">
             <img :src="img" />
           </li>
         </ul>
@@ -112,7 +117,7 @@
     </div>
     <div class="doc-content-more" v-if="articleList.length">
       <div class="doc-content-hd">
-        <h4 class="doc-content-title">更多内容</h4>
+        <h4 class="doc-content-title"></h4>
         <a class="sub-more" href="#/resource">More</a>
       </div>
       <ul class="more-list">
@@ -152,7 +157,8 @@ export default defineComponent({
       // theme: 'white',
       articleList,
       casesImages,
-      currentCaseItem
+      currentCaseItem,
+      localTheme: localStorage.getItem('nutui-theme-color')
     });
     onMounted(() => {
       // 文章列表接口
@@ -200,6 +206,11 @@ export default defineComponent({
         return `doc-content-${RefData.getInstance().themeColor.value}`;
       };
     });
+    const themeNameValue = computed(() => {
+      return function () {
+        return RefData.getInstance().themeColor.value;
+      };
+    });
     const toLink = (id: number) => {
       window.open('//jelly.jd.com/article/' + id);
     };
@@ -210,6 +221,7 @@ export default defineComponent({
       toIntro,
       ...toRefs(data),
       themeName,
+      themeNameValue,
       toLink,
       onLeft,
       onRight
@@ -419,17 +431,28 @@ export default defineComponent({
           height: 390px;
           flex-shrink: 0;
           margin-right: 20px;
-          box-shadow: 0px 1px 7px 0px #edeef1;
           transition: all 0.5s;
           &:first-child {
             margin-right: 139px;
             transform: scale(1.04);
+            border-radius: 10px;
+            overflow: hidden;
+          }
+          &:nth-child(-n + 4) {
+            box-shadow: 0 4px 7px 0 rgb(144 156 164 / 80%);
+            border-radius: 3px;
+            overflow: hidden;
           }
           > img {
             width: 100%;
             height: 100%;
           }
         }
+        &.noShadow {
+          > li {
+            box-shadow: none !important;
+          }
+        }
       }
     }
   }
@@ -595,11 +618,6 @@ export default defineComponent({
   .doc-content-cases-content__main {
     background: #474753;
   }
-  .doc-content-cases-content__list {
-    li {
-      box-shadow: none;
-    }
-  }
   .doc-content-more {
     .more-item img {
       box-shadow: none;

+ 1 - 1
src/sites/mobile-taro/vue/project.config.json

@@ -2,7 +2,7 @@
   "miniprogramRoot": "dist/",
   "projectname": "%40nutui%2Fnutui-taro-mobile",
   "description": "nutui-taro-vue",
-  "appid": "wxf2b976b67dab3882",
+  "appid": "wxee296c9bffc451d9",
   "setting": {
     "urlCheck": true,
     "es6": false,

+ 1 - 0
src/sites/mobile-taro/vue/src/app.config.ts

@@ -1,6 +1,7 @@
 export default {
   pages: [
     'pages/backtop/index',
+    'pages/drag/index',
     'pages/toast/index',
     'pages/notify/index',
     'pages/dialog/index',

+ 49 - 0
src/sites/mobile-taro/vue/src/pages/drag/index.vue

@@ -0,0 +1,49 @@
+<template>
+  <div class="demo full">
+    <h2>基础用法</h2>
+    <nut-drag
+      style="width: 90%; height: 200px; border: 1px solid red"
+      direction="all"
+      width="120"
+      height="40"
+    >
+      <nut-button style="width: 120px; height: 40px" type="primary"
+        >触摸移动</nut-button
+      >
+    </nut-drag>
+    <h2 style="margin: 60px 0 0 0">限制拖拽方向</h2>
+    <nut-drag
+      style="width: 100%; height: 200px; position: absolute"
+      direction="x"
+      width="120"
+      height="40"
+    >
+      <nut-button style="width: 120px; height: 40px" type="primary"
+        >只能X轴拖拽</nut-button
+      >
+    </nut-drag>
+    <nut-drag
+      style="
+        width: 100%;
+        height: 200px;
+        position: absolute;
+        margin: 0 0 0 200px;
+      "
+      direction="y"
+      width="120"
+      height="40"
+    >
+      <nut-button style="width: 120px; height: 40px" type="primary"
+        >只能y轴拖拽</nut-button
+      >
+    </nut-drag>
+  </div>
+</template>
+
+<script lang="ts">
+export default {
+  setup() {}
+};
+</script>
+
+<style lang="scss"></style>