| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576 |
- <!-- 移动端实验流程组件 -->
- <template>
- <view class="experiment-process-container">
- <view class="list-item" v-for="(item, index) in list" :key="item.id" :data-index="index">
- <!-- 组件内容 -->
- <view class="item-content">
- <customText :ref="'customTextRef' + item.id" v-if="item.type === 'customText'" :id="item.id"
- @calculation="calculation" :readonly="readonly">
- </customText>
- <customTable :ref="'customTextRef' + item.id" v-if="item.type == 'customTable'" :id="item.id"
- @calculation="calculation" :readonly="readonly">
- </customTable>
- </view>
- </view>
- </view>
- </template>
- <script>
- import customText from './customText.vue';
- import customTable from './customTable.vue';
- export default {
- components: {
- customText,
- customTable
- },
- props: {
- readonly: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- list: [],
- };
- },
- methods: {
- // 计算
- calculation() {
- this.getValue();
- let equation = [];
- this.list.forEach(item => {
- equation.push({
- id: item.id,
- equation: item.equation
- });
- });
- equation.forEach(item => {
- for (const key in item.equation) {
- let {
- data,
- units
- } = this.getObjValue();
- let value = '';
- if (item.equation[key].length) {
- item.equation[key].forEach(equationItem => {
- if (equationItem.type == 'symbol' || equationItem.type == 'value') {
- value += equationItem.value;
- } else if (equationItem.type == 'id') {
- value += Number(data[equationItem.value]) || 0;
- }
- });
- if (units[key]?.decimalPlace) {
- if (units[key]?.takeValueMethod) {
- value =
- units[key]?.takeValueMethod == 1 ?
- parseFloat(eval(value).toFixed(units[key].decimalPlace)) :
- this.truncateToFixedManual(eval(value), units[key].decimalPlace);
- } else {
- value = parseFloat(eval(value).toFixed(units[key].decimalPlace));
- }
- } else {
- value = parseFloat(eval(value).toFixed(2));
- }
- if (this.$refs['customTextRef' + item.id] && this.$refs['customTextRef' + item.id][
- 0
- ]) {
- this.$refs['customTextRef' + item.id][0].equationValue({
- domId: key,
- value
- });
- }
- }
- }
- });
- },
- truncateToFixedManual(num, decimalPlaces) {
- let factor = Math.pow(10, decimalPlaces);
- return Math.floor(num * factor) / factor;
- },
- getObjValue() {
- this.getValue();
- let data = {};
- let units = {};
- this.list.forEach(item => {
- units = {
- ...item.units,
- ...units
- };
- if (item.type == 'customText') {
- data = {
- ...item.valueObj,
- ...data
- };
- } else {
- item.valueObj.columns.forEach((row) => {
- row.forEach((cell) => {
- data[cell.id] = cell.value;
- });
- });
- }
- });
- return {
- data: data || {},
- units: units || {}
- };
- },
- // 初始化
- init(list) {
- if (!list) return;
- this.list = JSON.parse(list);
- if (this.list.length) {
- this.$nextTick(() => {
- setTimeout(() => {
- this.list.forEach(item => {
- if (this.$refs['customTextRef' + item.id] && this.$refs[
- 'customTextRef' + item.id][0]) {
- this.$refs['customTextRef' + item.id][0].init({
- form: item.value,
- valueObj: item.valueObj,
- equation: item.equation,
- units: item.units
- });
- }
- });
- }, 1200)
- });
- }
- },
- // 获取值
- getValue() {
- this.list.forEach((item, index) => {
- if (this.$refs['customTextRef' + item.id] && this.$refs['customTextRef' + item.id][0]) {
- let {
- form,
- valueObj,
- equation,
- units
- } = this.$refs['customTextRef' + item.id][0].getValue();
- this.$set(this.list[index], 'value', form);
- this.$set(this.list[index], 'valueObj', valueObj);
- this.$set(this.list[index], 'equation', equation);
- this.$set(this.list[index], 'units', units);
- }
- });
- return this.list;
- },
- }
- };
- </script>
- <style lang="scss" scoped>
- .experiment-process-container {
- width: 100%;
- overflow: hidden;
- .toolbar {
- display: flex;
- padding: 20rpx;
- background-color: #fff;
- border-bottom: 1rpx solid #e0e0e0;
- .toolbar-btn {
- flex: 1;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- padding: 20rpx;
- margin: 0 10rpx;
- background-color: #f5f5f5;
- border-radius: 8rpx;
- &:active {
- background-color: #e0e0e0;
- }
- .btn-icon {
- font-size: 40rpx;
- margin-bottom: 10rpx;
- }
- .btn-text {
- font-size: 24rpx;
- color: #333;
- }
- }
- }
- .drag-list {
- padding: 20rpx;
- min-height: 400rpx;
- .list-item {
- position: relative;
- margin-bottom: 20rpx;
- background-color: #fff;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- overflow: hidden;
- .item-actions {
- display: flex;
- justify-content: flex-end;
- padding: 10rpx;
- background-color: #f9f9f9;
- border-bottom: 1rpx solid #e0e0e0;
- .action-btn {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 50%;
- margin-left: 10rpx;
- .icon {
- font-size: 32rpx;
- color: #fff;
- }
- &.drag-handle {
- background-color: #409eff;
- }
- &.delete-btn {
- background-color: #f56c6c;
- }
- }
- }
- .item-content {
- padding: 20rpx;
- }
- }
- &.is-readonly {
- .item-actions {
- display: none;
- }
- }
- }
- // 配置面板
- .config-panel {
- background-color: #fff;
- border-radius: 20rpx 20rpx 0 0;
- padding: 30rpx;
- .panel-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding-bottom: 30rpx;
- border-bottom: 1rpx solid #e0e0e0;
- .header-title {
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- }
- .close-btn {
- width: 60rpx;
- height: 60rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- .close-icon {
- font-size: 60rpx;
- color: #999;
- line-height: 1;
- }
- }
- }
- .panel-body {
- padding: 30rpx 0;
- .form-item {
- margin-bottom: 30rpx;
- .label {
- display: block;
- font-size: 28rpx;
- color: #333;
- margin-bottom: 15rpx;
- }
- .form-input {
- width: 100%;
- height: 80rpx;
- padding: 0 20rpx;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- font-size: 28rpx;
- &:focus {
- border-color: #157a2c;
- }
- }
- .picker-value {
- height: 80rpx;
- line-height: 80rpx;
- padding: 0 20rpx;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- font-size: 28rpx;
- background-color: #fff;
- }
- .formula-display {
- padding: 20rpx;
- background-color: #f5f5f5;
- border-radius: 8rpx;
- margin-bottom: 15rpx;
- .formula-text {
- font-size: 28rpx;
- color: #333;
- word-break: break-all;
- }
- }
- .formula-actions {
- display: flex;
- gap: 20rpx;
- .action-btn {
- flex: 1;
- height: 70rpx;
- line-height: 70rpx;
- text-align: center;
- border-radius: 8rpx;
- font-size: 28rpx;
- &.primary {
- background-color: #157a2c;
- color: #fff;
- }
- &.danger {
- background-color: #f56c6c;
- color: #fff;
- }
- }
- }
- }
- }
- }
- // 公式弹窗
- .equation-popup {
- width: 650rpx;
- max-height: 80vh;
- background-color: #fff;
- border-radius: 16rpx;
- overflow: hidden;
- .popup-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 30rpx;
- border-bottom: 1rpx solid #e0e0e0;
- .header-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- }
- .close-btn {
- width: 50rpx;
- height: 50rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- .close-icon {
- font-size: 50rpx;
- color: #999;
- line-height: 1;
- }
- }
- }
- .popup-body {
- padding: 30rpx;
- max-height: 60vh;
- overflow-y: auto;
- .formula-selects {
- display: flex;
- gap: 20rpx;
- margin-bottom: 20rpx;
- .select-btn {
- flex: 1;
- height: 70rpx;
- line-height: 70rpx;
- padding: 0 20rpx;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- display: flex;
- justify-content: space-between;
- align-items: center;
- background-color: #fff;
- font-size: 26rpx;
- color: #333;
- .arrow {
- color: #999;
- }
- }
- }
- .value-input {
- display: flex;
- gap: 20rpx;
- margin-bottom: 20rpx;
- .form-input {
- flex: 1;
- height: 70rpx;
- padding: 0 20rpx;
- border: 1rpx solid #e0e0e0;
- border-radius: 8rpx;
- font-size: 28rpx;
- }
- .confirm-btn {
- width: 120rpx;
- height: 70rpx;
- line-height: 70rpx;
- text-align: center;
- background-color: #157a2c;
- color: #fff;
- border-radius: 8rpx;
- font-size: 28rpx;
- }
- }
- .equation-tags {
- display: flex;
- flex-wrap: wrap;
- gap: 15rpx;
- margin-bottom: 20rpx;
- min-height: 80rpx;
- padding: 20rpx;
- background-color: #f5f5f5;
- border-radius: 8rpx;
- .tag {
- position: relative;
- display: flex;
- align-items: center;
- padding: 10rpx 20rpx;
- background-color: #e0e0e0;
- border-radius: 20rpx;
- font-size: 26rpx;
- color: #333;
- &.active {
- background-color: #157a2c;
- color: #fff;
- }
- .close {
- margin-left: 10rpx;
- padding: 0 5rpx;
- font-size: 32rpx;
- }
- }
- }
- .formula-preview {
- padding: 20rpx;
- background-color: #f9f9f9;
- border-radius: 8rpx;
- .preview-text {
- font-size: 28rpx;
- color: #333;
- word-break: break-all;
- }
- }
- }
- .popup-footer {
- display: flex;
- gap: 20rpx;
- padding: 20rpx 30rpx 30rpx;
- border-top: 1rpx solid #e0e0e0;
- .footer-btn {
- flex: 1;
- height: 80rpx;
- line-height: 80rpx;
- text-align: center;
- border-radius: 8rpx;
- font-size: 32rpx;
- .btn-text {
- color: #fff;
- }
- &.cancel {
- background-color: #e0e0e0;
- .btn-text {
- color: #333;
- }
- }
- }
- }
- }
- }
- </style>
|