Browse Source

perf: 压缩代码

develop
song 4 years ago
parent
commit
b4fa681482
  1. 1
      CHANGELOG.md
  2. 201
      rest/project.http
  3. 2
      rest/燕园.http
  4. 10
      src/apis/plugin.js
  5. 3
      src/apis/project.js
  6. 9
      src/apis/yanyuan.js
  7. 101
      src/components/InputSearch/InputSearch.vue
  8. 22
      src/components/uni-popup/message.js
  9. 23
      src/components/uni-popup/popup.js
  10. 246
      src/components/uni-popup/uni-popup-dialog.vue
  11. 115
      src/components/uni-popup/uni-popup-message.vue
  12. 171
      src/components/uni-popup/uni-popup-share.vue
  13. 289
      src/components/uni-popup/uni-popup.vue
  14. 276
      src/components/uni-transition/uni-transition.vue

1
CHANGELOG.md

@ -146,6 +146,7 @@
- | 任务开始时间延迟插件 | [992a313](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/992a313)
- | 修改main | [749ae9a](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/749ae9a)
- | 修改props默认值 | [11b2c24](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/11b2c24)
- | 修改合并手机号逻辑 | [5d391a3](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/5d391a3)
- | 修改定期任务状态0和4时不加载圆圈 | [30e352f](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/30e352f)
- | 修改小红点传参 | [87b20fd](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/87b20fd)
- | 修改报错 | [531c14d](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/531c14d)

201
rest/project.http

@ -1,201 +0,0 @@
@localhost = http://localhost:7260/v2.0
@localhost_tall = http://localhost:7130/v3.0
@test_tall = http://192.168.0.99:7130/v3.0
@test = https://test.tall.wiki/gateway/yanyuan/v2.0/
@www_tall = http://www.tall.wiki:7130/v3.0
@www = http://www.tall.wiki/gateway/yanyuan/v2.0/
@type = content-type: application/json;charset=utf-8
### 登录
# @name login
POST {{test_tall}}/users/signin
{{type}}
{
"client": 1,
"type": 3,
"data": {
"identifier": "song",
"credential": "999999"
}
}
### debug
GET {{test}}/debug
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
###绑定工具箱
POST {{test}}/tool/bind
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"toolCode":"0000000003"
}
}
###查询登录用户身份
POST {{test}}/userPower/identity
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
}
###添加用户信息
POST {{test}}/trainee/add
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"userName":"李四",
"sex":"1",
"clinicHospital":"就诊医院",
"hospitalProvinceId":"1",
"hospitalCityId":"2",
"hospitalAddress":"迎泽区XXX",
"clinicOffice":"神经内科",
"clinicDoctor":"赵医生",
"birthDate":"1965-08-01",
"height":"170",
"weight":"66",
"jobTitle":"农林渔牧",
"educateStatus":"小学",
"educateDate":"6",
"abodePlace":"太原市小店区",
"appearTime":"2021-01-01",
"diagnoseTime":"2021-02-01",
"diagnoseResult":"轻度痴呆",
"minBloodPressure":"90",
"maxBloodPressure":"120",
"bloodFat":"80",
"physicalAct":"中",
"apoeGene":"1",
"diseasesRecord":"没有疾病史",
"relativeDiseasesRecord":"亲属均无老年痴呆",
"isInsomnic":0,
"insomnicPeriod":"8",
"isSmoke":1,
"quitPeriod":2,
"sustainPeriod":3,
"averageNum":5,
"isDrink":2,
"abstinencePeriod":"2年",
"drinkType":"啤酒",
"isTea":"3",
"quitTea":"",
"continuePeriod":"1年",
"teaType":"绿茶",
"teaPeriod":"每天一杯",
"isStrongFlavour":1,
"isLikeMeat":1,
"isMoreOil":0
}
}
###查询绑定者创建的患者信息(申请成为家属前调用)
POST {{test}}/trainee/create
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"bindUserId":"1218025249493356544"
}
}
###绑定手机号后,关联用户原有的使用者
POST {{test}}/trainee/relation
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
}
###生成二维码
POST {{test}}/tool/qrCode
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"id":"1"
}
}
###体验账号升级
POST {{test}}/trainee/upgrade
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"keyUserIds":[
"1456525052375470081"
]
}
}
###查询个人信息
POST {{test}}/family/personal
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
}
###申请成为家属
POST {{test}}/family/apply
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"keyUserIds":[
"1456525052375470080",
"1456525052375470081"
],
"age":25,
"educateLevel": "本科",
"jobTitle": "码农",
"name": "小伙伴",
"sex": 1
}
}
###查询试题
POST {{test}}/question/get
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"code":"NLCP",
"reportId": "1458968153773838336",
"num": "1"
}
}
###保存答案
POST {{localhost}}/question/saveAnswer
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"code":"NLCP",
"reportId": "1459057596971094016",
"questionId": "21",
"optionId": "1"
}
}
###脑力测评结果计算
POST {{localhost}}/mentalTest/calculate
{{type}}
Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"mentalTestId": "1459057596971094016"
}
}

2
rest/燕园.http

@ -121,7 +121,7 @@ Authorization: Bearer {{login.response.body.$.data.token}}
{
"param":{
"id":"1"
"id":"6"
}
}
###体验账号升级

10
src/apis/plugin.js

@ -5,16 +5,6 @@ const install = (Vue, vm) => {
vm.$u.api = { ...vm.$u.api } || {};
// 获取插件信息
vm.$u.api.getOtherPlugin = param => vm.$u.post(`${url}/pluginshop/plugin/query?pluginId=${param.pluginId}&styleType=${param.styleType}`);
// 查询子任务
vm.$u.api.findSonTask = param => vm.$u.post(`${uni.$t.domain}/task/findSonTask`, param);
// 查询子项目
vm.$u.api.findSonProject = param => vm.$u.post(`${uni.$t.domain}/project/findSonProject`, param);
// 提交交付物
vm.$u.api.saveDeliver = param => vm.$u.post(`${uni.$t.domain}/deliver/save`, param);
// 查询任务的交付物历史记录
vm.$u.api.queryDeliverOfTask = param => vm.$u.post(`${uni.$t.domain}/deliver/queryDeliverOfTask`, param);
// 检查交付物
vm.$u.api.checkDeliver = param => vm.$u.post(`${uni.$t.domain}/deliver/checkDeliver`, param);
};
export default { install };

3
src/apis/project.js

@ -8,9 +8,6 @@ const install = (Vue, vm) => {
//点击分享连接
vm.$u.api.clickShare = param => vm.$u.post(`${uni.$t.domain}/share/click`, param);
//查询医院是否填写了调查问卷
vm.$u.api.queryNotWrite = param => vm.$u.post(`${uni.$t.domain}/questionnaire/queryNotWrite`, param);
};
export default { install };

9
src/apis/yanyuan.js

@ -8,10 +8,6 @@ const install = (Vue, vm) => {
vm.$u.api.addTrainee = param => vm.$u.post(`${yanyuan}/trainee/add`, param);
// 查询用户创建的老人信息
vm.$u.api.createTrainee = param => vm.$u.post(`${yanyuan}/trainee/create`, param);
// 查询体验账号
vm.$u.api.experienceTrainee = param => vm.$u.post(`${yanyuan}/trainee/experience`, param);
// 绑定手机号后,关联用户原有的使用者
vm.$u.api.relationTrainee = param => vm.$u.post(`${yanyuan}/trainee/relation`, param);
// 体验账号升级
vm.$u.api.upgradeTrainee = param => vm.$u.post(`${yanyuan}/trainee/upgrade`, param);
// 查询用户信息
@ -23,14 +19,9 @@ const install = (Vue, vm) => {
// 绑定工具箱
vm.$u.api.bindTool = param => vm.$u.post(`${yanyuan}/tool/bind`, param);
// 查询指定工具箱二维码
vm.$u.api.qrCode = param => vm.$u.post(`${yanyuan}/tool/qrCode`, param);
// 查询工具箱列表
vm.$u.api.queryToolList = param => vm.$u.post(`${yanyuan}/tool/queryToolList`, param);
// 用户身份判断
vm.$u.api.identityUserPower = param => vm.$u.post(`${yanyuan}/userPower/identity`, param);
// 试题查询
vm.$u.api.getQuestion = param => vm.$u.post(`${yanyuan}/question/get`, param);
// 试题答案保存

101
src/components/InputSearch/InputSearch.vue

@ -1,101 +0,0 @@
<template>
<view class="input-group flex-1">
<input :placeholder="placeholder" @input="search" @blur="hideList" v-model="backName" />
<view class="ul">
<view class="li" v-for="(item, index) in dataSource" :key="index" @tap="select(item)">{{ item.name }}</view>
</view>
</view>
</template>
<script>
export default {
props: {
placeholder: String, //
searchKey: String, //key
dataSource: {
type: Array,
default: function () {
//
return [];
},
},
},
data() {
return {
list: [],
name: '',
backName: '',
};
},
destroyed() {
clearTimeout(this.t);
},
methods: {
search(e) {
let val = e.detail.value;
console.log('val: ', val);
this.$emit('searchPrevTask', val);
// let arr = [];
// for (let i = 0; i < dataSource.length; i++) {
// if (dataSource[i].name.indexOf(val) !== -1) {
// arr.push(dataSource[i]);
// }
// }
// if (!val) {
// this.list = [];
// } else {
// this.list = arr;
// }
},
select(item) {
console.log('item: ', item);
this.backName = item.name;
this.$emit('select', item);
},
hideList() {
setTimeout(() => {
this.$emit('clearAllTasks');
}, 200);
},
},
};
</script>
<style lang="scss" scoped>
.input-group {
position: relative;
input {
border-bottom: 1upx solid #dcdfe6;
height: 90upx;
padding-left: 10upx;
font-size: 30upx;
box-sizing: border-box;
}
.uni-input-placeholder {
color: rgb(192, 196, 204);
font-size: 28upx;
}
.ul {
position: absolute;
left: 0;
top: 100%;
width: 100%;
z-index: 999;
background: #fff;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
max-height: 100px;
overflow-y: auto;
.li {
border-bottom: 1upx solid #f1f1f1;
padding: 16upx;
}
}
}
</style>

22
src/components/uni-popup/message.js

@ -1,22 +0,0 @@
export default {
created() {
if (this.type === 'message') {
// 不显示遮罩
this.maskShow = false;
// 获取子组件对象
this.childrenMsg = null;
}
},
methods: {
customOpen() {
if (this.childrenMsg) {
this.childrenMsg.open();
}
},
customClose() {
if (this.childrenMsg) {
this.childrenMsg.close();
}
},
},
};

23
src/components/uni-popup/popup.js

@ -1,23 +0,0 @@
import message from './message.js';
// 定义 type 类型:弹出类型:top/bottom/center
const config = {
// 顶部弹出
top: 'top',
// 底部弹出
bottom: 'bottom',
// 居中弹出
center: 'center',
// 消息提示
message: 'top',
// 对话框
dialog: 'center',
// 分享
share: 'bottom',
};
export default {
data() {
return { config: config };
},
mixins: [message],
};

246
src/components/uni-popup/uni-popup-dialog.vue

@ -1,246 +0,0 @@
<template>
<view class="uni-popup-dialog">
<view class="uni-dialog-title">
<text class="uni-dialog-title-text" :class="['uni-popup__' + dialogType]">{{ title }}</text>
</view>
<view class="uni-dialog-content">
<text class="uni-dialog-content-text" v-if="mode === 'base'">{{ content }}</text>
<input v-else class="uni-dialog-input" v-model="val" type="text" :placeholder="placeholder" :focus="focus" />
</view>
<view class="uni-dialog-button-group">
<view class="uni-dialog-button" @click="close">
<text class="uni-dialog-button-text">取消</text>
</view>
<view class="uni-dialog-button uni-border-left" @click="onOk">
<text class="uni-dialog-button-text uni-button-color">确定</text>
</view>
</view>
</view>
</template>
<script>
/**
* PopUp 弹出层-对话框样式
* @description 弹出层-对话框样式
* @tutorial https://ext.dcloud.net.cn/plugin?id=329
* @property {String} value input 模式下的默认值
* @property {String} placeholder input 模式下输入提示
* @property {String} type = [success|warning|info|error] 主题样式
* @value success 成功
* @value warning 提示
* @value info 消息
* @value error 错误
* @property {String} mode = [base|input] 模式
* @value base 基础对话框
* @value input 可输入对话框
* @property {String} content 对话框内容
* @property {Boolean} beforeClose 是否拦截取消事件
* @event {Function} confirm 点击确认按钮触发
* @event {Function} close 点击取消按钮触发
*/
export default {
name: 'uniPopupDialog',
props: {
value: {
type: [String, Number],
default: '',
},
placeholder: {
type: [String, Number],
default: '请输入内容',
},
/**
* 对话框主题 success/warning/info/error 默认 success
*/
type: {
type: String,
default: 'error',
},
/**
* 对话框模式 base/input
*/
mode: {
type: String,
default: 'base',
},
/**
* 对话框标题
*/
title: {
type: String,
default: '提示',
},
/**
* 对话框内容
*/
content: {
type: String,
default: '',
},
/**
* 拦截取消事件 如果拦截取消事件必须监听close事件执行 done()
*/
beforeClose: {
type: Boolean,
default: false,
},
},
data() {
return {
dialogType: 'error',
focus: false,
val: '',
};
},
inject: ['popup'],
watch: {
type(val) {
this.dialogType = val;
},
mode(val) {
if (val === 'input') {
this.dialogType = 'info';
}
},
value(val) {
this.val = val;
},
},
created() {
//
this.popup.mkclick = false;
if (this.mode === 'input') {
this.dialogType = 'info';
this.val = this.value;
} else {
this.dialogType = this.type;
}
},
mounted() {
this.focus = true;
},
methods: {
/**
* 点击确认按钮
*/
onOk() {
this.$emit(
'confirm',
() => {
this.popup.close();
if (this.mode === 'input') this.val = this.value;
},
this.mode === 'input' ? this.val : '',
);
},
/**
* 点击取消按钮
*/
close() {
if (this.beforeClose) {
this.$emit('close', () => {
this.popup.close();
});
return;
}
this.popup.close();
},
},
};
</script>
<style lang="scss" scoped>
.uni-popup-dialog {
width: 300px;
border-radius: 15px;
background-color: #fff;
}
.uni-dialog-title {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: center;
padding-top: 15px;
padding-bottom: 5px;
}
.uni-dialog-title-text {
font-size: 16px;
font-weight: 500;
}
.uni-dialog-content {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: center;
align-items: center;
padding: 5px 15px 15px 15px;
}
.uni-dialog-content-text {
font-size: 14px;
color: #6e6e6e;
}
.uni-dialog-button-group {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
border-top-color: #f5f5f5;
border-top-style: solid;
border-top-width: 1px;
}
.uni-dialog-button {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex: 1;
flex-direction: row;
justify-content: center;
align-items: center;
height: 45px;
}
.uni-border-left {
border-left-color: #f0f0f0;
border-left-style: solid;
border-left-width: 1px;
}
.uni-dialog-button-text {
font-size: 14px;
}
.uni-button-color {
color: $uni-color-primary;
}
.uni-dialog-input {
flex: 1;
font-size: 14px;
}
.uni-popup__success {
color: $uni-color-success;
}
.uni-popup__warn {
color: $uni-color-warning;
}
.uni-popup__error {
color: $uni-color-error;
}
.uni-popup__info {
color: #909399;
}
</style>

115
src/components/uni-popup/uni-popup-message.vue

@ -1,115 +0,0 @@
<template>
<view class="uni-popup-message" :class="'uni-popup__' + [type]">
<text class="uni-popup-message-text" :class="'uni-popup__' + [type] + '-text'">{{ message }}</text>
</view>
</template>
<script>
/**
* PopUp 弹出层-消息提示
* @description 弹出层-消息提示
* @tutorial https://ext.dcloud.net.cn/plugin?id=329
* @property {String} type = [success|warning|info|error] 主题样式
* @value success 成功
* @value warning 提示
* @value info 消息
* @value error 错误
* @property {String} message 消息提示文字
* @property {String} duration 显示时间设置为 0 则不会自动关闭
*/
export default {
name: 'UniPopupMessage',
props: {
/**
* 主题 success/warning/info/error 默认 success
*/
type: {
type: String,
default: 'success',
},
/**
* 消息文字
*/
message: {
type: String,
default: '',
},
/**
* 显示时间设置为 0 则不会自动关闭
*/
duration: {
type: Number,
default: 3000,
},
},
inject: ['popup'],
data() {
return {};
},
created() {
this.popup.childrenMsg = this;
},
methods: {
open() {
if (this.duration === 0) return;
clearTimeout(this.popuptimer);
this.popuptimer = setTimeout(() => {
this.popup.close();
}, this.duration);
},
close() {
clearTimeout(this.popuptimer);
},
},
};
</script>
<style lang="scss" scoped>
.uni-popup-message {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
background-color: #e1f3d8;
padding: 10px 15px;
border-color: #eee;
border-style: solid;
border-width: 1px;
}
.uni-popup-message-text {
font-size: 14px;
padding: 0;
}
.uni-popup__success {
background-color: #e1f3d8;
}
.uni-popup__success-text {
color: #67c23a;
}
.uni-popup__warn {
background-color: #faecd8;
}
.uni-popup__warn-text {
color: #e6a23c;
}
.uni-popup__error {
background-color: #fde2e2;
}
.uni-popup__error-text {
color: #f56c6c;
}
.uni-popup__info {
background-color: #f2f6fc;
}
.uni-popup__info-text {
color: #909399;
}
</style>

171
src/components/uni-popup/uni-popup-share.vue

@ -1,171 +0,0 @@
<template>
<view class="uni-popup-share">
<view class="uni-share-title">
<text class="uni-share-title-text">{{ title }}</text>
</view>
<view class="uni-share-content">
<view class="uni-share-content-box">
<view class="uni-share-content-item" v-for="(item, index) in bottomData" :key="index" @click.stop="select(item, index)">
<image class="uni-share-image" :src="item.icon" mode="aspectFill"></image>
<text class="uni-share-text">{{ item.text }}</text>
</view>
</view>
</view>
<view class="uni-share-button-box">
<button class="uni-share-button" @click="close">取消</button>
</view>
</view>
</template>
<script>
export default {
name: 'UniPopupShare',
props: {
title: {
type: String,
default: '分享到',
},
},
inject: ['popup'],
data() {
return {
bottomData: [
{
text: '微信',
icon: 'https://img-cdn-qiniu.dcloud.net.cn/uni-ui/grid-2.png',
name: 'wx',
},
{
text: '支付宝',
icon: 'https://img-cdn-qiniu.dcloud.net.cn/uni-ui/grid-8.png',
name: 'wx',
},
{
text: 'QQ',
icon: 'https://img-cdn-qiniu.dcloud.net.cn/uni-ui/gird-3.png',
name: 'qq',
},
{
text: '新浪',
icon: 'https://img-cdn-qiniu.dcloud.net.cn/uni-ui/grid-1.png',
name: 'sina',
},
{
text: '百度',
icon: 'https://img-cdn-qiniu.dcloud.net.cn/uni-ui/grid-7.png',
name: 'copy',
},
{
text: '其他',
icon: 'https://img-cdn-qiniu.dcloud.net.cn/uni-ui/grid-5.png',
name: 'more',
},
],
};
},
created() {},
methods: {
/**
* 选择内容
*/
select(item, index) {
this.$emit(
'select',
{
item,
index,
},
() => {
this.popup.close();
},
);
},
/**
* 关闭窗口
*/
close() {
this.popup.close();
},
},
};
</script>
<style lang="scss" scoped>
.uni-popup-share {
background-color: #fff;
}
.uni-share-title {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
justify-content: center;
height: 40px;
}
.uni-share-title-text {
font-size: 14px;
color: #666;
}
.uni-share-content {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: center;
padding-top: 10px;
}
.uni-share-content-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
flex-wrap: wrap;
width: 360px;
}
.uni-share-content-item {
width: 90px;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
padding: 10px 0;
align-items: center;
}
.uni-share-content-item:active {
background-color: #f5f5f5;
}
.uni-share-image {
width: 30px;
height: 30px;
}
.uni-share-text {
margin-top: 10px;
font-size: 14px;
color: #3b4144;
}
.uni-share-button-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
padding: 10px 15px;
}
.uni-share-button {
flex: 1;
border-radius: 50px;
color: #666;
font-size: 16px;
}
.uni-share-button::after {
border-radius: 50px;
}
</style>

289
src/components/uni-popup/uni-popup.vue

@ -1,289 +0,0 @@
<template>
<view v-if="showPopup" class="uni-popup" :class="[popupstyle]" @touchmove.stop.prevent="clear">
<uni-transition v-if="maskShow" :mode-class="['fade']" :styles="maskClass" :duration="duration" :show="showTrans" @click="onTap" />
<uni-transition :mode-class="ani" :styles="transClass" :duration="duration" :show="showTrans" @click="onTap">
<view class="uni-popup__wrapper-box" @click.stop="clear">
<slot />
</view>
</uni-transition>
</view>
</template>
<script>
import uniTransition from '../uni-transition/uni-transition.vue';
import popup from './popup.js';
/**
* PopUp 弹出层
* @description 弹出层组件为了解决遮罩弹层的问题
* @tutorial https://ext.dcloud.net.cn/plugin?id=329
* @property {String} type = [top|center|bottom] 弹出方式
* @value top 顶部弹出
* @value center 中间弹出
* @value bottom 底部弹出
* @value message 消息提示
* @value dialog 对话框
* @value share 底部分享示例
* @property {Boolean} animation = [ture|false] 是否开启动画
* @property {Boolean} maskClick = [ture|false] 蒙版点击是否关闭弹窗
* @event {Function} change 打开关闭弹窗触发e={show: false}
*/
export default {
name: 'UniPopup',
components: { uniTransition },
props: {
//
animation: {
type: Boolean,
default: true,
},
// top: bottomcenter
// message: ; dialog :
type: {
type: String,
default: 'center',
},
// maskClick
maskClick: {
type: Boolean,
default: true,
},
},
provide() {
return { popup: this };
},
mixins: [popup],
watch: {
/**
* 监听type类型
*/
type: {
handler: function (newVal) {
this[this.config[newVal]]();
},
immediate: true,
},
/**
* 监听遮罩是否可点击
* @param {Object} val
*/
maskClick(val) {
this.mkclick = val;
},
},
data() {
return {
duration: 300,
ani: [],
showPopup: false,
showTrans: false,
maskClass: {
position: 'fixed',
bottom: 0,
top: 0,
left: 0,
right: 0,
backgroundColor: 'rgba(0, 0, 0, 0.4)',
},
transClass: {
position: 'fixed',
left: 0,
right: 0,
},
maskShow: true,
mkclick: true,
popupstyle: 'top',
};
},
created() {
this.mkclick = this.maskClick;
if (this.animation) {
this.duration = 300;
} else {
this.duration = 0;
}
},
methods: {
clear(e) {
// TODO nvue
e.stopPropagation();
},
open() {
this.showPopup = true;
this.$nextTick(() => {
new Promise(resolve => {
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.showTrans = true;
// fixed by mehaotian app
this.$nextTick(() => {
resolve();
});
}, 50);
}).then(res => {
console.log('res: ', res);
//
clearTimeout(this.msgtimer);
this.msgtimer = setTimeout(() => {
this.customOpen && this.customOpen();
}, 100);
this.$emit('change', {
show: true,
type: this.type,
});
});
});
},
close(type) {
this.showTrans = false;
this.$nextTick(() => {
this.$emit('change', {
show: false,
type,
});
clearTimeout(this.timer);
//
this.customOpen && this.customClose();
this.timer = setTimeout(() => {
this.showPopup = false;
}, 300);
});
},
onTap() {
if (!this.mkclick) return;
this.close();
},
/**
* 顶部弹出样式处理
*/
top() {
this.popupstyle = 'top';
this.ani = ['slide-top'];
this.transClass = {
position: 'fixed',
left: 0,
right: 0,
};
},
/**
* 底部弹出样式处理
*/
bottom() {
this.popupstyle = 'bottom';
this.ani = ['slide-bottom'];
this.transClass = {
position: 'fixed',
left: 0,
right: 0,
bottom: 0,
};
},
/**
* 中间弹出样式处理
*/
center() {
this.popupstyle = 'center';
this.ani = ['zoom-out', 'fade'];
this.transClass = {
position: 'fixed',
/* #ifndef APP-NVUE */
display: 'flex',
flexDirection: 'column',
/* #endif */
bottom: 0,
left: 0,
right: 0,
top: 0,
justifyContent: 'center',
alignItems: 'center',
};
},
},
};
</script>
<style lang="scss" scoped>
.uni-popup {
position: fixed;
/* #ifndef APP-NVUE */
z-index: 99;
/* #endif */
}
.uni-popup__mask {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: $uni-bg-color-mask;
opacity: 0;
}
.mask-ani {
transition-property: opacity;
transition-duration: 0.2s;
}
.uni-top-mask {
opacity: 1;
}
.uni-bottom-mask {
opacity: 1;
}
.uni-center-mask {
opacity: 1;
}
.uni-popup__wrapper {
/* #ifndef APP-NVUE */
display: block;
/* #endif */
position: absolute;
}
.top {
/* #ifdef H5 */
top: var(--window-top);
/* #endif */
/* #ifndef H5 */
top: 0;
/* #endif */
}
.bottom {
bottom: 0;
}
.uni-popup__wrapper-box {
/* #ifndef APP-NVUE */
display: block;
/* #endif */
position: relative;
/* iphonex 等安全区设置,底部安全区适配 */
/* #ifndef APP-NVUE */
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
/* #endif */
}
.content-ani {
// transition: transform 0.3s;
transition-property: transform, opacity;
transition-duration: 0.2s;
}
.uni-top-content {
transform: translateY(0);
}
.uni-bottom-content {
transform: translateY(0);
}
.uni-center-content {
transform: scale(1);
opacity: 1;
}
</style>

276
src/components/uni-transition/uni-transition.vue

@ -1,276 +0,0 @@
<template>
<view
v-if="isShow"
ref="ani"
class="uni-transition"
:class="[ani.in]"
:style="'transform:' + transform + ';' + stylesObject"
@click="change"
>
<slot></slot>
</view>
</template>
<script>
// #ifdef APP-NVUE
const animation = uni.requireNativePlugin('animation');
// #endif
/**
* Transition 过渡动画
* @description 简单过渡动画组件
* @tutorial https://ext.dcloud.net.cn/plugin?id=985
* @property {Boolean} show = [false|true] 控制组件显示或隐藏
* @property {Array} modeClass = [fade|slide-top|slide-right|slide-bottom|slide-left|zoom-in|zoom-out] 过渡动画类型
* @value fade 渐隐渐出过渡
* @value slide-top 由上至下过渡
* @value slide-right 由右至左过渡
* @value slide-bottom 由下至上过渡
* @value slide-left 由左至右过渡
* @value zoom-in 由小到大过渡
* @value zoom-out 由大到小过渡
* @property {Number} duration 过渡动画持续时间
* @property {Object} styles 组件样式 css 样式注意带-连接符的属性需要使用小驼峰写法如`backgroundColor:red`
*/
export default {
name: 'uniTransition',
props: {
show: {
type: Boolean,
default: false,
},
modeClass: {
type: Array,
default() {
return [];
},
},
duration: {
type: Number,
default: 300,
},
styles: {
type: Object,
default() {
return {};
},
},
},
data() {
return {
isShow: false,
transform: '',
ani: { in: '', active: '' },
};
},
watch: {
show: {
handler(newVal) {
if (newVal) {
this.open();
} else {
this.close();
}
},
immediate: true,
},
},
computed: {
stylesObject() {
let styles = {
...this.styles,
'transition-duration': this.duration / 1000 + 's',
};
let transfrom = '';
for (let i in styles) {
let line = this.toLine(i);
transfrom += line + ':' + styles[i] + ';';
}
return transfrom;
},
},
created() {
// this.timer = null
// this.nextTick = (time = 50) => new Promise(resolve => {
// clearTimeout(this.timer)
// this.timer = setTimeout(resolve, time)
// return this.timer
// });
},
methods: {
change() {
this.$emit('click', { detail: this.isShow });
},
open() {
clearTimeout(this.timer);
this.isShow = true;
this.transform = '';
this.ani.in = '';
for (let i in this.getTranfrom(false)) {
if (i === 'opacity') {
this.ani.in = 'fade-in';
} else {
this.transform += `${this.getTranfrom(false)[i]} `;
}
}
this.$nextTick(() => {
setTimeout(() => {
this._animation(true);
}, 50);
});
},
close() {
clearTimeout(this.timer);
this._animation(false);
},
_animation(type) {
let styles = this.getTranfrom(type);
// #ifdef APP-NVUE
if (!this.$refs['ani']) return;
animation.transition(
this.$refs['ani'].ref,
{
styles,
duration: this.duration, //ms
timingFunction: 'ease',
needLayout: false,
delay: 0, //ms
},
() => {
if (!type) {
this.isShow = false;
}
this.$emit('change', { detail: this.isShow });
},
);
// #endif
// #ifndef APP-NVUE
this.transform = '';
for (let i in styles) {
if (i === 'opacity') {
this.ani.in = `fade-${type ? 'out' : 'in'}`;
} else {
this.transform += `${styles[i]} `;
}
}
this.timer = setTimeout(() => {
if (!type) {
this.isShow = false;
}
this.$emit('change', { detail: this.isShow });
}, this.duration);
// #endif
},
getTranfrom(type) {
let styles = { transform: '' };
this.modeClass.forEach(mode => {
switch (mode) {
case 'fade':
styles.opacity = type ? 1 : 0;
break;
case 'slide-top':
styles.transform += `translateY(${type ? '0' : '-100%'}) `;
break;
case 'slide-right':
styles.transform += `translateX(${type ? '0' : '100%'}) `;
break;
case 'slide-bottom':
styles.transform += `translateY(${type ? '0' : '100%'}) `;
break;
case 'slide-left':
styles.transform += `translateX(${type ? '0' : '-100%'}) `;
break;
case 'zoom-in':
styles.transform += `scale(${type ? 1 : 0.8}) `;
break;
case 'zoom-out':
styles.transform += `scale(${type ? 1 : 1.2}) `;
break;
}
});
return styles;
},
_modeClassArr(type) {
let mode = this.modeClass;
if (typeof mode !== 'string') {
let modestr = '';
mode.forEach(item => {
modestr += item + '-' + type + ',';
});
return modestr.substr(0, modestr.length - 1);
} else {
return mode + '-' + type;
}
},
// getEl(el) {
// console.log(el || el.ref || null);
// return el || el.ref || null
// },
toLine(name) {
return name.replace(/([A-Z])/g, '-$1').toLowerCase();
},
},
};
</script>
<style>
.uni-transition {
transition-timing-function: ease;
transition-duration: 0.3s;
transition-property: transform, opacity;
}
.fade-in {
opacity: 0;
}
.fade-active {
opacity: 1;
}
.slide-top-in {
/* transition-property: transform, opacity; */
transform: translateY(-100%);
}
.slide-top-active {
transform: translateY(0);
/* opacity: 1; */
}
.slide-right-in {
transform: translateX(100%);
}
.slide-right-active {
transform: translateX(0);
}
.slide-bottom-in {
transform: translateY(100%);
}
.slide-bottom-active {
transform: translateY(0);
}
.slide-left-in {
transform: translateX(-100%);
}
.slide-left-active {
transform: translateX(0);
opacity: 1;
}
.zoom-in-in {
transform: scale(0.8);
}
.zoom-out-active {
transform: scale(1);
}
.zoom-out-in {
transform: scale(1.2);
}
</style>
Loading…
Cancel
Save