experimentationProcess.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <!-- 移动端实验流程组件 -->
  2. <template>
  3. <view class="experiment-process-container">
  4. <view class="list-item" v-for="(item, index) in list" :key="item.id" :data-index="index">
  5. <!-- 组件内容 -->
  6. <view class="item-content">
  7. <customText :ref="'customTextRef' + item.id" v-if="item.type === 'customText'" :id="item.id"
  8. @calculation="calculation" :readonly="readonly">
  9. </customText>
  10. <customTable :ref="'customTextRef' + item.id" v-if="item.type == 'customTable'" :id="item.id"
  11. @calculation="calculation" :readonly="readonly">
  12. </customTable>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import customText from './customText.vue';
  19. import customTable from './customTable.vue';
  20. export default {
  21. components: {
  22. customText,
  23. customTable
  24. },
  25. props: {
  26. readonly: {
  27. type: Boolean,
  28. default: false
  29. }
  30. },
  31. data() {
  32. return {
  33. list: [],
  34. };
  35. },
  36. methods: {
  37. // 计算
  38. calculation() {
  39. this.getValue();
  40. let equation = [];
  41. this.list.forEach(item => {
  42. equation.push({
  43. id: item.id,
  44. equation: item.equation
  45. });
  46. });
  47. equation.forEach(item => {
  48. for (const key in item.equation) {
  49. let {
  50. data,
  51. units
  52. } = this.getObjValue();
  53. let value = '';
  54. if (item.equation[key].length) {
  55. item.equation[key].forEach(equationItem => {
  56. if (equationItem.type == 'symbol' || equationItem.type == 'value') {
  57. value += equationItem.value;
  58. } else if (equationItem.type == 'id') {
  59. value += Number(data[equationItem.value]) || 0;
  60. }
  61. });
  62. if (units[key]?.decimalPlace) {
  63. if (units[key]?.takeValueMethod) {
  64. value =
  65. units[key]?.takeValueMethod == 1 ?
  66. parseFloat(eval(value).toFixed(units[key].decimalPlace)) :
  67. this.truncateToFixedManual(eval(value), units[key].decimalPlace);
  68. } else {
  69. value = parseFloat(eval(value).toFixed(units[key].decimalPlace));
  70. }
  71. } else {
  72. value = parseFloat(eval(value).toFixed(2));
  73. }
  74. if (this.$refs['customTextRef' + item.id] && this.$refs['customTextRef' + item.id][
  75. 0
  76. ]) {
  77. this.$refs['customTextRef' + item.id][0].equationValue({
  78. domId: key,
  79. value
  80. });
  81. }
  82. }
  83. }
  84. });
  85. },
  86. truncateToFixedManual(num, decimalPlaces) {
  87. let factor = Math.pow(10, decimalPlaces);
  88. return Math.floor(num * factor) / factor;
  89. },
  90. getObjValue() {
  91. this.getValue();
  92. let data = {};
  93. let units = {};
  94. this.list.forEach(item => {
  95. units = {
  96. ...item.units,
  97. ...units
  98. };
  99. if (item.type == 'customText') {
  100. data = {
  101. ...item.valueObj,
  102. ...data
  103. };
  104. } else {
  105. item.valueObj.columns.forEach((row) => {
  106. row.forEach((cell) => {
  107. data[cell.id] = cell.value;
  108. });
  109. });
  110. }
  111. });
  112. return {
  113. data: data || {},
  114. units: units || {}
  115. };
  116. },
  117. // 初始化
  118. init(list) {
  119. if (!list) return;
  120. this.list = JSON.parse(list);
  121. if (this.list.length) {
  122. this.$nextTick(() => {
  123. setTimeout(() => {
  124. this.list.forEach(item => {
  125. if (this.$refs['customTextRef' + item.id] && this.$refs[
  126. 'customTextRef' + item.id][0]) {
  127. this.$refs['customTextRef' + item.id][0].init({
  128. form: item.value,
  129. valueObj: item.valueObj,
  130. equation: item.equation,
  131. units: item.units
  132. });
  133. }
  134. });
  135. }, 1200)
  136. });
  137. }
  138. },
  139. // 获取值
  140. getValue() {
  141. this.list.forEach((item, index) => {
  142. if (this.$refs['customTextRef' + item.id] && this.$refs['customTextRef' + item.id][0]) {
  143. let {
  144. form,
  145. valueObj,
  146. equation,
  147. units
  148. } = this.$refs['customTextRef' + item.id][0].getValue();
  149. this.$set(this.list[index], 'value', form);
  150. this.$set(this.list[index], 'valueObj', valueObj);
  151. this.$set(this.list[index], 'equation', equation);
  152. this.$set(this.list[index], 'units', units);
  153. }
  154. });
  155. return this.list;
  156. },
  157. }
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .experiment-process-container {
  162. width: 100%;
  163. overflow: hidden;
  164. .toolbar {
  165. display: flex;
  166. padding: 20rpx;
  167. background-color: #fff;
  168. border-bottom: 1rpx solid #e0e0e0;
  169. .toolbar-btn {
  170. flex: 1;
  171. display: flex;
  172. flex-direction: column;
  173. align-items: center;
  174. justify-content: center;
  175. padding: 20rpx;
  176. margin: 0 10rpx;
  177. background-color: #f5f5f5;
  178. border-radius: 8rpx;
  179. &:active {
  180. background-color: #e0e0e0;
  181. }
  182. .btn-icon {
  183. font-size: 40rpx;
  184. margin-bottom: 10rpx;
  185. }
  186. .btn-text {
  187. font-size: 24rpx;
  188. color: #333;
  189. }
  190. }
  191. }
  192. .drag-list {
  193. padding: 20rpx;
  194. min-height: 400rpx;
  195. .list-item {
  196. position: relative;
  197. margin-bottom: 20rpx;
  198. background-color: #fff;
  199. border: 1rpx solid #e0e0e0;
  200. border-radius: 8rpx;
  201. overflow: hidden;
  202. .item-actions {
  203. display: flex;
  204. justify-content: flex-end;
  205. padding: 10rpx;
  206. background-color: #f9f9f9;
  207. border-bottom: 1rpx solid #e0e0e0;
  208. .action-btn {
  209. width: 60rpx;
  210. height: 60rpx;
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. border-radius: 50%;
  215. margin-left: 10rpx;
  216. .icon {
  217. font-size: 32rpx;
  218. color: #fff;
  219. }
  220. &.drag-handle {
  221. background-color: #409eff;
  222. }
  223. &.delete-btn {
  224. background-color: #f56c6c;
  225. }
  226. }
  227. }
  228. .item-content {
  229. padding: 20rpx;
  230. }
  231. }
  232. &.is-readonly {
  233. .item-actions {
  234. display: none;
  235. }
  236. }
  237. }
  238. // 配置面板
  239. .config-panel {
  240. background-color: #fff;
  241. border-radius: 20rpx 20rpx 0 0;
  242. padding: 30rpx;
  243. .panel-header {
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: center;
  247. padding-bottom: 30rpx;
  248. border-bottom: 1rpx solid #e0e0e0;
  249. .header-title {
  250. font-size: 36rpx;
  251. font-weight: bold;
  252. color: #333;
  253. }
  254. .close-btn {
  255. width: 60rpx;
  256. height: 60rpx;
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. .close-icon {
  261. font-size: 60rpx;
  262. color: #999;
  263. line-height: 1;
  264. }
  265. }
  266. }
  267. .panel-body {
  268. padding: 30rpx 0;
  269. .form-item {
  270. margin-bottom: 30rpx;
  271. .label {
  272. display: block;
  273. font-size: 28rpx;
  274. color: #333;
  275. margin-bottom: 15rpx;
  276. }
  277. .form-input {
  278. width: 100%;
  279. height: 80rpx;
  280. padding: 0 20rpx;
  281. border: 1rpx solid #e0e0e0;
  282. border-radius: 8rpx;
  283. font-size: 28rpx;
  284. &:focus {
  285. border-color: #157a2c;
  286. }
  287. }
  288. .picker-value {
  289. height: 80rpx;
  290. line-height: 80rpx;
  291. padding: 0 20rpx;
  292. border: 1rpx solid #e0e0e0;
  293. border-radius: 8rpx;
  294. font-size: 28rpx;
  295. background-color: #fff;
  296. }
  297. .formula-display {
  298. padding: 20rpx;
  299. background-color: #f5f5f5;
  300. border-radius: 8rpx;
  301. margin-bottom: 15rpx;
  302. .formula-text {
  303. font-size: 28rpx;
  304. color: #333;
  305. word-break: break-all;
  306. }
  307. }
  308. .formula-actions {
  309. display: flex;
  310. gap: 20rpx;
  311. .action-btn {
  312. flex: 1;
  313. height: 70rpx;
  314. line-height: 70rpx;
  315. text-align: center;
  316. border-radius: 8rpx;
  317. font-size: 28rpx;
  318. &.primary {
  319. background-color: #157a2c;
  320. color: #fff;
  321. }
  322. &.danger {
  323. background-color: #f56c6c;
  324. color: #fff;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. // 公式弹窗
  332. .equation-popup {
  333. width: 650rpx;
  334. max-height: 80vh;
  335. background-color: #fff;
  336. border-radius: 16rpx;
  337. overflow: hidden;
  338. .popup-header {
  339. display: flex;
  340. justify-content: space-between;
  341. align-items: center;
  342. padding: 30rpx;
  343. border-bottom: 1rpx solid #e0e0e0;
  344. .header-title {
  345. font-size: 32rpx;
  346. font-weight: bold;
  347. color: #333;
  348. }
  349. .close-btn {
  350. width: 50rpx;
  351. height: 50rpx;
  352. display: flex;
  353. align-items: center;
  354. justify-content: center;
  355. .close-icon {
  356. font-size: 50rpx;
  357. color: #999;
  358. line-height: 1;
  359. }
  360. }
  361. }
  362. .popup-body {
  363. padding: 30rpx;
  364. max-height: 60vh;
  365. overflow-y: auto;
  366. .formula-selects {
  367. display: flex;
  368. gap: 20rpx;
  369. margin-bottom: 20rpx;
  370. .select-btn {
  371. flex: 1;
  372. height: 70rpx;
  373. line-height: 70rpx;
  374. padding: 0 20rpx;
  375. border: 1rpx solid #e0e0e0;
  376. border-radius: 8rpx;
  377. display: flex;
  378. justify-content: space-between;
  379. align-items: center;
  380. background-color: #fff;
  381. font-size: 26rpx;
  382. color: #333;
  383. .arrow {
  384. color: #999;
  385. }
  386. }
  387. }
  388. .value-input {
  389. display: flex;
  390. gap: 20rpx;
  391. margin-bottom: 20rpx;
  392. .form-input {
  393. flex: 1;
  394. height: 70rpx;
  395. padding: 0 20rpx;
  396. border: 1rpx solid #e0e0e0;
  397. border-radius: 8rpx;
  398. font-size: 28rpx;
  399. }
  400. .confirm-btn {
  401. width: 120rpx;
  402. height: 70rpx;
  403. line-height: 70rpx;
  404. text-align: center;
  405. background-color: #157a2c;
  406. color: #fff;
  407. border-radius: 8rpx;
  408. font-size: 28rpx;
  409. }
  410. }
  411. .equation-tags {
  412. display: flex;
  413. flex-wrap: wrap;
  414. gap: 15rpx;
  415. margin-bottom: 20rpx;
  416. min-height: 80rpx;
  417. padding: 20rpx;
  418. background-color: #f5f5f5;
  419. border-radius: 8rpx;
  420. .tag {
  421. position: relative;
  422. display: flex;
  423. align-items: center;
  424. padding: 10rpx 20rpx;
  425. background-color: #e0e0e0;
  426. border-radius: 20rpx;
  427. font-size: 26rpx;
  428. color: #333;
  429. &.active {
  430. background-color: #157a2c;
  431. color: #fff;
  432. }
  433. .close {
  434. margin-left: 10rpx;
  435. padding: 0 5rpx;
  436. font-size: 32rpx;
  437. }
  438. }
  439. }
  440. .formula-preview {
  441. padding: 20rpx;
  442. background-color: #f9f9f9;
  443. border-radius: 8rpx;
  444. .preview-text {
  445. font-size: 28rpx;
  446. color: #333;
  447. word-break: break-all;
  448. }
  449. }
  450. }
  451. .popup-footer {
  452. display: flex;
  453. gap: 20rpx;
  454. padding: 20rpx 30rpx 30rpx;
  455. border-top: 1rpx solid #e0e0e0;
  456. .footer-btn {
  457. flex: 1;
  458. height: 80rpx;
  459. line-height: 80rpx;
  460. text-align: center;
  461. border-radius: 8rpx;
  462. font-size: 32rpx;
  463. .btn-text {
  464. color: #fff;
  465. }
  466. &.cancel {
  467. background-color: #e0e0e0;
  468. .btn-text {
  469. color: #333;
  470. }
  471. }
  472. }
  473. }
  474. }
  475. }
  476. </style>