index.vue 3.84 KB
<!--
 * @Date: 2022-09-19 14:11:06
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2022-09-19 17:21:39
 * @FilePath: /swx/src/pages/index/index.vue
 * @Description: 文件描述
-->
<template>
  <!-- <van-tabs :active="active" bind:change="onChange">
    <van-tab title="标签 1">内容 2</van-tab>
    <van-tab title="标签 2">内容 2</van-tab>
    <van-tab title="标签 3">内容 3</van-tab>
    <van-tab title="标签 4">
      <van-button type="primary" @click="goTo">主要按钮</van-button>
    </van-tab>
  </van-tabs> -->
  <van-button type="primary" @click="goTo">主要按钮</van-button>
  <van-image width="100" height="100" src="https://img.yzcdn.cn/vant/cat.jpeg" />
  <view class="page-body">
    <view class="page-section">
      <text>时间日期选择器--无默认</text>
      <view>
        <timePickerData
          :start-time="startTime"
          :end-time="endTime"
          @result="onResult"
        >
          <input placeholder="请选择" disabled='true' :value="time" />
        </timePickerData>
      </view>
    </view>
  </view>
</template>

<script setup>
import Taro from '@tarojs/taro'
import { ref } from 'vue';
import request from '../../utils/request';
import timePickerData from "@/components/time-picker-data/picker";

request.get('/srv/?a=kg_list')
.then(res => {
  console.warn(res);
})
.catch(err => {
  console.error(err);
})
// Taro.request({
//   url: 'http://voice.onwall.cn/srv/?f=voice&a=kg_list', //仅为示例,并非真实的接口地址
//   data: {
//   },
//   // header: {
//   //   'content-type': 'application/json' // 默认值
//   // },
//   success: function (res) {
//     console.log(res.data)
//   }
// })
const active = ref(1);

const goTo = () => {
  Taro.navigateTo({
    url: '../demo/index?id=1'
  })
}
</script>

<script>
import "./index.less";
export default {
  name: "indexPage",
  onReady() {
    if (!Taro.canIUse("getUpdateManager")) {
      Taro.showModal({
        title: "提示",
        content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试",
        showCancel: false,
      });
      return;
    }

    // https://developers.weixin.qq.com/miniprogram/dev/api/base/update/UpdateManager.html
    const updateManager = Taro.getUpdateManager();

    updateManager.onCheckForUpdate((res) => {
      // 请求完新版本信息的回调
      if (res.hasUpdate) {
        updateManager.onUpdateReady(function () {
          Taro.showModal({
            title: "更新提示",
            content: "新版本已经准备好,是否重启应用?",
            success: function (res) {
              if (res.confirm) {
                // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                updateManager.applyUpdate();
              }
            },
          });
        });

        updateManager.onUpdateFailed(function () {
          // 新版本下载失败
          Taro.showModal({
            title: "更新提示",
            content: "新版本已上线,请删除当前小程序,重新搜索打开",
          });
        });
      }
    });
  },
  data() {
    return {
      time:'',
      startTime: new Date(),
      default:new Date(),
    };
  },
  created(){
     this.startTime = this.getTime("min", 1);
      this.endTime = this.getTime("year", 2);
  },
  methods: {
      getTime(key, number, date) {
      let _date = date ? new Date(date) : new Date();
      if (key === "min") {
        _date.setMinutes(_date.getMinutes() + number);
      }
      if (key === "hour") {
        _date.setHours(_date.getHours() + number);
      }
      if (key === "year") {
        _date.setFullYear(_date.getFullYear() + number);
      }
      return _date;
    },
    onResult(arr) {
      let time =
        arr[0] + "-" + arr[1] + "-" + arr[2] + " " + arr[3] + ":" + arr[4];
        this.time = time;
    },
  },
};
</script>