Browse Source

fix: 修改添加基本信息 压缩代码

develop
song 4 years ago
parent
commit
ce20ff7674
  1. 1
      .prettierignore
  2. 1
      CHANGELOG.md
  3. 2
      src/App.vue
  4. 3666
      src/common/u-charts.min.js
  5. 176
      src/components/Info/Info.vue
  6. 6
      src/config/yyInfo.js
  7. 162
      src/pagesYanyuan/add-info/add-info.vue
  8. 24
      src/test/util/task.test.js
  9. 46
      src/test/util/time.test.js
  10. 1
      src/uni.scss

1
.prettierignore

@ -8,3 +8,4 @@ package.json
postcss.config.js
.eslint.js
*.scss
u-charts.min.js

1
CHANGELOG.md

@ -249,6 +249,7 @@
- | 修改代码格式 | [14123d7](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/14123d7)
- | 修改定期任务骨架屏高度 | [909a734](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/909a734)
- | 修改时间轴自动滚动到当天任务的时间 | [20bbf6a](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/20bbf6a)
- | 压缩代码 | [b4fa681](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/b4fa681)
- | 压缩代码,提交体验版 | [c5f50ff](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/c5f50ff)
- | 小红点api缓存修改 | [e992343](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/e992343)
- | 提交本地代码 | [e0cf2ed](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/e0cf2ed)

2
src/App.vue

@ -98,6 +98,8 @@ export default {
</style>
<style>
@import '@/common/styles/tailwind.scss';
.collapse-box >>> .u-collapse-body {
height: auto !important;
}

3666
src/common/u-charts.min.js

File diff suppressed because one or more lines are too long

176
src/components/Info/Info.vue

@ -317,6 +317,9 @@
</template>
<view class="w-full h-2 bg-gray-100" v-if="index !== infoList.length - 1"></view>
</view>
<view class="p-4 bg" v-if="!isEdit">
<u-button type="primary" class="w-full" @click="submit">完成</u-button>
</view>
</view>
</template>
@ -457,9 +460,8 @@ export default {
}
this.$t.storage.setStorageSync('infoList', this.infoList);
if (!this.isEdit) {
this.$emit('saveInfo', info);
} else {
if (this.isEdit) {
this.updateTrainee(info);
}
},
@ -474,9 +476,8 @@ export default {
}
}
info[type] = e;
if (!this.isEdit) {
this.$emit('saveInfo', info);
} else {
if (this.isEdit) {
this.updateTrainee(info);
}
},
@ -515,6 +516,169 @@ export default {
}
},
//
submit() {
if (!this.AddvalidationRequired()) return;
const params = this.saveInfo();
this.$emit('submit', params, this.infoList);
},
//
saveInfo() {
const params = {};
for (let i = 0; i < this.infoList.length; i++) {
const item = this.infoList[i];
for (let j = 0; j < item.length; j++) {
const info = item[j];
//
params.apoeGene = '0';
params.isInsomnic = 0;
params.isSmoke = 0;
params.isDrink = 0;
params.isTea = 0;
params.isStrongFlavour = 0;
params.isMoreOil = 0;
//
params[info.label] = info.value;
//
if (info.value === '其他' && info.showOther && info.otherValue) {
params[info.label] = info.otherValue;
}
//
if (info.showType === 1 && info.type === 5) {
let arrValue = '';
if (info.showOther && info.otherValue) {
const index = info.value.indexOf('其他');
info.value.splice(index, 1, '其他:' + info.otherValue);
}
arrValue = info.value.toString();
params[info.label] = arrValue;
}
//
if (info.label === 'BloodPressure') {
const arr = info.value.split('/');
params.minBloodPressure = arr[0];
params.maxBloodPressure = arr[1];
}
//
if (info.type === 9) {
params.hospitalCityId = info.hospitalCityId;
params.hospitalProvinceId = info.hospitalProvinceId;
}
//
if (info.type === 10) {
params.insomnicPeriod = info.value1;
}
//
if (info.type === 11) {
params.quitPeriod = info.value1;
params.sustainPeriod = info.value2;
params.averageNum = info.value3;
}
//
if (info.type === 12) {
params.abstinencePeriod = info.value1;
if (info.classesValue) {
params.drinkType = info.classesValue;
if (info.classesValue === '其他' && info.showOther && info.otherValue) {
params.drinkType = info.otherValue;
}
}
}
//
if (info.type === 13) {
params.quitTea = info.value1;
params.continuePeriod = info.value2;
params.teaType = info.classesValue;
params.teaPeriod = info.frequencyValue;
}
}
}
return params;
},
//
AddvalidationRequired() {
let isComplete = true;
for (let i = 0; i < this.infoList.length; i++) {
const info = this.infoList[i];
for (let j = 0; j < info.length; j++) {
const item = info[j];
if (item.type !== 5) {
if (item.value === null) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
if (item.showOther && !item.otherValue) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
if (item.type === 10 || item.type === 11 || item.type === 12 || item.type === 13) {
if (item.value === 1 && !item.value1) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
}
if (item.showClasses && !item.classesValue) {
this.$t.ui.showToast(`请填写${item.name}种类`);
isComplete = false;
break;
}
if (item.type === 13) {
if (item.showClasses && !item.frequencyValue) {
this.$t.ui.showToast(`请填写${item.name}频率`);
isComplete = false;
break;
}
}
if (item.type === 11) {
if (item.value === 2) {
if (!item.value2) {
this.$t.ui.showToast(`请填写烟龄`);
isComplete = false;
break;
}
if (!item.value3) {
this.$t.ui.showToast(`请填写每天抽烟数量`);
isComplete = false;
break;
}
}
}
if (item.type === 13) {
if (item.value === 2 && !item.value2) {
this.$t.ui.showToast(`请填写持续喝茶时长`);
isComplete = false;
break;
}
}
} else {
if (item.value.length === 0) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
if (item.showOther && !item.otherValue) {
this.$t.ui.showToast(`请填写其他${item.name}`);
isComplete = false;
break;
}
}
}
if (!isComplete) {
break;
}
}
if (isComplete) return true;
},
//
setDate(date) {
if (!date || !date.userName) return;

6
src/config/yyInfo.js

@ -184,7 +184,7 @@ export const infoList = [
{ id: '1', value: '是' },
{ id: '2', value: '不知道' },
],
value: '',
value: '0',
show: true,
},
],
@ -297,7 +297,7 @@ export const infoList = [
{ id: 0, value: '否' },
{ id: 1, value: '是' },
],
value: '否',
value: 0,
show: true,
},
{
@ -321,7 +321,7 @@ export const infoList = [
{ id: 0, value: '否' },
{ id: 1, value: '是' },
],
value: '否',
value: 0,
show: true,
},
],

162
src/pagesYanyuan/add-info/add-info.vue

@ -1,10 +1,8 @@
<template>
<view>
<u-top-tips ref="uTips" type="success"></u-top-tips>
<Info class="bg-white" @saveInfo="saveInfo" />
<view class="p-4 bg">
<u-button type="primary" class="w-full" @click="submit">完成</u-button>
</view>
<Info class="bg-white" @submit="submit" />
<view class="w-full bg text-gray-200 text-center pt-4 pb-12">----------我也是有底线的----------</view>
</view>
</template>
@ -15,89 +13,19 @@ import { infoList } from '@/config/yyInfo';
export default {
data() {
return { params: {}, infoList };
return { infoList };
},
computed: mapState('yanyuan', ['isApplying']),
methods: {
//
saveInfo(info) {
//
this.params.apoeGene = '0';
this.params.isInsomnic = 0;
this.params.isSmoke = 0;
this.params.isDrink = 0;
this.params.isTea = 0;
this.params.isStrongFlavour = 0;
this.params.isMoreOil = 0;
//
this.params[info.label] = info.value;
//
if (info.value === '其他' && info.showOther && info.otherValue) {
this.params[info.label] = info.otherValue;
}
//
if (info.showType === 1 && info.type === 5) {
let arrValue = '';
if (info.showOther && info.otherValue) {
const index = info.value.indexOf('其他');
info.value.splice(index, 1, '其他:' + info.otherValue);
}
arrValue = info.value.toString();
this.params[info.label] = arrValue;
}
//
if (info.label === 'BloodPressure') {
const arr = info.value.split('/');
this.params.minBloodPressure = arr[0];
this.params.maxBloodPressure = arr[1];
}
//
if (info.type === 9) {
this.params.hospitalCityId = info.hospitalCityId;
this.params.hospitalProvinceId = info.hospitalProvinceId;
}
//
if (info.type === 10) {
this.params.insomnicPeriod = info.value1;
}
//
if (info.type === 11) {
this.params.quitPeriod = info.value1;
this.params.sustainPeriod = info.value2;
this.params.averageNum = info.value3;
}
//
if (info.type === 12) {
this.params.abstinencePeriod = info.value1;
if (info.classesValue) {
this.params.drinkType = info.classesValue;
if (info.classesValue === '其他' && info.showOther && info.otherValue) {
this.params.drinkType = info.otherValue;
}
}
}
//
if (info.type === 13) {
this.params.quitTea = info.value1;
this.params.continuePeriod = info.value2;
this.params.teaType = info.classesValue;
this.params.teaPeriod = info.frequencyValue;
}
},
/**
* 提交用户信息
* @param { object } params
*/
async submit() {
async submit(params, infoList) {
try {
const params = this.params;
if (!this.validationRequired(params)) return;
this.infoList = infoList;
await this.$u.api.addTrainee(params);
if (this.isApplying) {
this.$refs.uTips.show({
@ -115,92 +43,14 @@ export default {
setTimeout(() => {
uni.redirectTo({ url: '/pages/index/index' });
this.setEmptyInfo();
this.$t.storage.setStorageSync('infoList', null);
}, 2000);
}
this.$t.storage.setStorageSync('infoList', null);
} catch (error) {
console.error('error: ', error);
}
},
//
validationRequired() {
let isComplete = true;
for (let i = 0; i < this.infoList.length; i++) {
const info = this.infoList[i];
for (let j = 0; j < info.length; j++) {
const item = info[j];
if (item.type !== 5) {
if (item.value === null) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
if (item.showOther && !item.otherValue) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
if (item.type === 10 || item.type === 11 || item.type === 12 || item.type === 13) {
if (item.value === 1 && !item.value1) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
}
if (item.showClasses && !item.classesValue) {
this.$t.ui.showToast(`请填写${item.name}种类`);
isComplete = false;
break;
}
if (item.type === 13) {
if (item.showClasses && !item.frequencyValue) {
this.$t.ui.showToast(`请填写${item.name}频率`);
isComplete = false;
break;
}
}
if (item.type === 11) {
if (item.value === 2) {
if (!item.value2) {
this.$t.ui.showToast(`请填写烟龄`);
isComplete = false;
break;
}
if (!item.value3) {
this.$t.ui.showToast(`请填写每天抽烟数量`);
isComplete = false;
break;
}
}
}
if (item.type === 13) {
if (item.value === 2 && !item.value2) {
this.$t.ui.showToast(`请填写持续喝茶时长`);
isComplete = false;
break;
}
}
} else {
if (item.value.length === 0) {
this.$t.ui.showToast(`请填写${item.name}`);
isComplete = false;
break;
}
if (item.showOther && !item.otherValue) {
this.$t.ui.showToast(`请填写其他${item.name}`);
isComplete = false;
break;
}
}
}
if (!isComplete) {
break;
}
}
if (isComplete) return true;
},
//
setEmptyInfo() {
this.infoList.forEach(info => {

24
src/test/util/task.test.js

@ -1,24 +0,0 @@
import { computeFillPlaceholderTaskCount } from '../../utils/task';
describe('computeFillPlaceholderTaskCount', () => {
// 2021/8/17 ~ 2021/8/21
const tasks = [
{ id: '99724910037144221455', panel: {}, plugins: [], process: 4, planStart: 1629169800242 },
{ id: '65053357415671253512', panel: {}, plugins: [], process: 4, planStart: 1629256200242 },
{ id: '38735454515347179194', panel: {}, plugins: [], process: 4, planStart: 1629342600242 },
{ id: '49602681534756706607', panel: {}, plugins: [], process: 4, planStart: 1629429000242 },
{ id: '98860265376222512018', panel: {}, plugins: [], process: 4, planStart: 1629515400242 },
{ id: '44419041575700334936', panel: {}, plugins: [], process: 4, planStart: 1629601800242 },
];
const timeGranularity = 'day';
it('超出上限 补齐', () => {
const data = [{ planStart: `${new Date('2021/8/10').getTime()}` }, { planStart: `${new Date('2021/8/11').getTime()}` }];
expect(computeFillPlaceholderTaskCount({ tasks, data, timeGranularity }).prev.toString()).toMatch(/(7|8)/);
});
it('超出下限 补齐', () => {
const data = [{ planStart: `${new Date('2021/8/10').getTime()}` }, { planStart: `${new Date('2021/8/22').getTime()}` }];
expect(computeFillPlaceholderTaskCount({ tasks, data, timeGranularity }).next.toString()).toMatch(/(1|2)/);
});
});

46
src/test/util/time.test.js

@ -1,46 +0,0 @@
import Time from '../../utils/time.js';
// 测试计算进行中剩余时长显示数值
describe('utils/time.js computeDurationText function', () => {
const { computeDurationText } = Time;
// const leftTime = +realStart + +planDuration - Date.now(); // 剩余时间
it ('leftTime is 60ms, num=60, time=16', () => {
expect(computeDurationText(60)).toEqual({ num: 60, time: 16 })
})
it ('leftTime is 300ms, num=300, time=16', () => {
expect(computeDurationText(300)).toEqual({ num: 300, time: 16 })
})
it ('leftTime is 10s20ms, num=10, time=1000', () => {
expect(computeDurationText(10*1000 + 20)).toEqual({ num: 10, time: 1000 })
})
it ('leftTime is 8分钟10s20ms, num=8, time=1000', () => {
expect(computeDurationText(8*60*1000 + 10*1000 + 20)).toEqual({ num: 8, time: 1000 })
})
it ('leftTime is 3小时8分钟10s20ms, num=3, time=1000', () => {
expect(computeDurationText(3*60*60*1000 + 8*60*1000 + 10*1000 + 20)).toEqual({ num: 3, time: 1000 })
})
it ('leftTime is 11天3小时8分钟10s20ms, num=11, time=60 * 60 * 1000', () => {
expect(computeDurationText(11*24*60*60*1000 + 3*60*60*1000 + 8*60*1000 + 10*1000 + 20)).toEqual({ num: 11, time: 60 * 60 * 1000 })
})
it ('leftTime is 2个月11天3小时8分钟10s20ms, num=2, time=60 * 60 * 1000', () => {
expect(computeDurationText(2*30*24*60*60*1000 + 11*24*60*60*1000 + 3*60*60*1000 + 8*60*1000 + 10*1000 + 20)).toEqual({ num: 2, time: 60 * 60 * 1000 })
})
it ('leftTime is 7年2个月11天3小时8分钟10s20ms, num=7, time=60 * 60 * 1000', () => {
expect(computeDurationText(7*12*30*24*60*60*1000 + 2*30*24*60*60*1000 + 11*24*60*60*1000 + 3*60*60*1000 + 8*60*1000 + 10*1000 + 20)).toEqual({ num: 7, time: 60 * 60 * 1000 })
})
it ('leftTime <=0, num=0, time=null', () => {
expect(computeDurationText(-10)).toEqual({ num: 0, time: null })
})
it ('leftTime 不是数字, num=0, time=null', () => {
expect(computeDurationText('abc')).toEqual({ num: 0, time: null })
})
})

1
src/uni.scss

@ -12,7 +12,6 @@
* 如果你的项目同样使用了scss预处理你也可以直接在你的 scss 代码中使用如下变量同时无需 import 这个文件
*/
@import 'uview-ui/theme.scss';
@import './common/styles/tailwind.scss';
/* 颜色变量 */ /* 行为相关颜色 */
$uni-color-primary: #1890ff;

Loading…
Cancel
Save