Xbar-R.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. <template>
  2. <div class="container1">
  3. <div class="databox">
  4. <el-scrollbar :style="{ height: Height + 'px' }">
  5. <div class="box" v-show="!addStatus">
  6. <div
  7. style="
  8. display: flex;
  9. align-items: center;
  10. justify-content: space-between;
  11. "
  12. >
  13. <div style="display: flex; align-items: center">
  14. <div class="bg"></div>
  15. 控制图绘制
  16. </div>
  17. <el-button
  18. type="primary"
  19. v-print="'#print'"
  20. style="margin-left: 10px; height: 25px"
  21. >打 印</el-button
  22. >
  23. </div>
  24. <div class="info">
  25. <div id="print">
  26. <div id="charts" :style="{ height: maxHeight / 2 + 'px' }"></div>
  27. <div id="charts1" :style="{ height: maxHeight / 2 + 'px' }"></div>
  28. </div>
  29. </div>
  30. </div>
  31. </el-scrollbar>
  32. </div>
  33. </div>
  34. </template>
  35. <script setup>
  36. import * as echarts from "echarts";
  37. import { useDictionaryStore } from "@/store";
  38. const props = defineProps({
  39. process: {
  40. type: String,
  41. required: true,
  42. },
  43. });
  44. const { dicts } = useDictionaryStore();
  45. const opOptions = ref([...dicts.spc_operation]);
  46. const value = ref(opOptions.value[0].remark);
  47. const Y1value = ref([]);
  48. const X1array = ref([]);
  49. const setY1value = () => {
  50. Y1value.value = [];
  51. tableData.value.forEach((item) => {
  52. Y1value.value.push(item.avg);
  53. });
  54. Y1value.value.unshift("");
  55. Y1value.value.push("");
  56. chartsOption1.value.series[0].data = Y1value.value;
  57. };
  58. const tableData = ref([]);
  59. const setX1array = async () => {
  60. X1array.value = await [];
  61. tableData.value.forEach((item, index) => {
  62. X1array.value.push(index + 1);
  63. });
  64. X1array.value.unshift("");
  65. X1array.value.push("");
  66. chartsOption1.value.xAxis[0].data = X1array.value;
  67. };
  68. const setChart1Info = () => {
  69. // chartsOption1.value.title[0].text = `上限=${showData.value.avgMax ? showData.value.avgMax : "-"}`;
  70. // chartsOption1.value.title[0].text = `x̄=${showData.value.avgAvg ? showData.value.avgAvg : "-"}`;
  71. chartsOption1.value.series[0].markLine.data[0].yAxis = JSON.parse(
  72. value.value
  73. ).avgMax;
  74. chartsOption1.value.series[0].markLine.data[0].label.formatter = `上限=${
  75. JSON.parse(value.value).avgMax ? JSON.parse(value.value).avgMax : "0"
  76. }`;
  77. chartsOption1.value.series[0].markLine.data[1].yAxis = JSON.parse(value.value)
  78. .avgMin
  79. ? JSON.parse(value.value).avgMin
  80. : 0;
  81. chartsOption1.value.series[0].markLine.data[1].label.formatter = `下限=${JSON.parse(value.value).avgMin ? JSON.parse(value.value).avgMin : "0"}`;
  82. chartsOption1.value.series[0].markLine.data[2].yAxis = JSON.parse(
  83. value.value
  84. ).avgMid;
  85. chartsOption1.value.series[0].markLine.data[2].label.formatter = `x̄=${
  86. JSON.parse(value.value).avgMid
  87. }`;
  88. // chartsOption1.value.title[2].text = `下限=${showData.value.avgMin ? showData.value.avgMin : "0"}`;
  89. };
  90. const setChart2Info = () => {
  91. // chartsOption2.value.title[0].text = `上限=${showData.value.rangeMax ? showData.value.rangeMax : "-"}`;
  92. // chartsOption2.value.title[0].text = `R=${showData.value.rangeAvg ? showData.value.rangeAvg : "-"}`;
  93. chartsOption2.value.series[0].markLine.data[0].yAxis = JSON.parse(
  94. value.value
  95. ).rangeMax;
  96. chartsOption2.value.series[0].markLine.data[0].label.formatter = `上限=${
  97. JSON.parse(value.value).rangeMax ? JSON.parse(value.value).rangeMax : "0"
  98. }`;
  99. chartsOption2.value.series[0].markLine.data[1].yAxis = JSON.parse(value.value)
  100. .rangeMin
  101. ? JSON.parse(value.value).rangeMin
  102. : 0;
  103. chartsOption2.value.series[0].markLine.data[1].label.formatter = `下限=${
  104. JSON.parse(value.value).rangeMin ? JSON.parse(value.value).rangeMin : "0"
  105. }`;
  106. chartsOption2.value.series[0].markLine.data[2].yAxis = JSON.parse(
  107. value.value
  108. ).rangeMid;
  109. chartsOption2.value.series[0].markLine.data[2].label.formatter = `x̄=${
  110. JSON.parse(value.value).rangeMid
  111. }`;
  112. // chartsOption2.value.title[2].text = `下限=${showData.value.rangeMin ? showData.value.rangeMin : "0"}`;
  113. };
  114. const setChart1 = () => {
  115. setChart1Info();
  116. setY1value();
  117. setX1array();
  118. charts1.value.setOption(chartsOption1.value, true);
  119. };
  120. const setChart2 = () => {
  121. setChart2Info();
  122. setY2value();
  123. setX2array();
  124. charts2.value.setOption(chartsOption2.value, true);
  125. };
  126. const title = ref("调阻精度");
  127. const showLable = ref("调阻");
  128. const changeSelect = () => {
  129. setTimeout(async () => {
  130. // showLable.value = selectRef.value.currentPlaceholder;
  131. // opOptions.value.forEach((item) => {
  132. // if (item.dictLabel == showLable.value) {
  133. // lableValue.value = item.dictValue;
  134. // }
  135. // });
  136. switch (process) {
  137. case "调阻":
  138. title.value = "调阻精度";
  139. break;
  140. case "粘片":
  141. title.value = "剪切强度";
  142. break;
  143. case "键合":
  144. title.value = "键合强度";
  145. break;
  146. default:
  147. title.value = "调阻精度";
  148. break;
  149. }
  150. // await getTableData();
  151. chartsOption1.value.title[0].text = `${title.value}的Xbar-R控制图`;
  152. setChart1();
  153. setChart2();
  154. }, 0);
  155. };
  156. const maxHeight = ref(null);
  157. const maxWidth = ref(null);
  158. const charts1 = shallowRef(null);
  159. const charts2 = shallowRef(null);
  160. const chartsOption1 = ref({
  161. title: [
  162. // {
  163. // text: `x̄=${showData.value.avgAvg ? showData.value.avgAvg : "-"}`,
  164. // right: "5%",
  165. // top: "42%",
  166. // textStyle: {
  167. // fontSize: 15,
  168. // color: "#333",
  169. // fontWeight: 100,
  170. // },
  171. // },
  172. {
  173. text: `${title.value}的Xbar-R控制图`,
  174. left: "40%",
  175. },
  176. {
  177. text: "均",
  178. left: "4%",
  179. top: "42%",
  180. },
  181. {
  182. text: "值",
  183. left: "4%",
  184. top: "49%",
  185. },
  186. ],
  187. grid: {
  188. right: "15%",
  189. },
  190. toolbox: {
  191. feature: {
  192. saveAsImage: {},
  193. },
  194. },
  195. tooltip: {
  196. show: true,
  197. },
  198. xAxis: [
  199. {
  200. type: "category",
  201. boundaryGap: false,
  202. data: [],
  203. },
  204. ],
  205. yAxis: [
  206. {
  207. type: "value",
  208. },
  209. ],
  210. series: [
  211. {
  212. type: "line",
  213. lineStyle: {
  214. color: "rgb(26, 122, 240)",
  215. },
  216. symbolSize: 13,
  217. symbol: "circle",
  218. itemStyle: {
  219. color: (params) => {
  220. const avg = JSON.parse(value.value);
  221. const paramValue = Number(params.value);
  222. if (
  223. paramValue <= Number(avg.avgMax) &&
  224. paramValue >= Number(avg.avgMin)
  225. ) {
  226. return "rgb(26, 122, 240)";
  227. } else {
  228. return "red";
  229. }
  230. },
  231. },
  232. markLine: {
  233. silent: true,
  234. data: [
  235. {
  236. silent: false,
  237. yAxis: 0,
  238. label: {
  239. position: "end",
  240. formatter: `上限=${JSON.parse(value.value).avgMax ? JSON.parse(value.value).avgMax : "-"}`,
  241. color: "#333",
  242. },
  243. lineStyle: { type: "solid", color: "#333", width: 2 },
  244. },
  245. {
  246. silent: false,
  247. yAxis: 0,
  248. label: {
  249. position: "end",
  250. formatter: `下限=${JSON.parse(value.value).avgMin ? JSON.parse(value.value).avgMin : "-"}`,
  251. color: "#333",
  252. },
  253. lineStyle: {
  254. type: "solid",
  255. color: "#333",
  256. width: 2,
  257. },
  258. },
  259. {
  260. yAxis: 0,
  261. silent: false,
  262. label: {
  263. position: "end",
  264. formatter: ``,
  265. color: "#333",
  266. },
  267. lineStyle: {
  268. type: "solid",
  269. color: "#333",
  270. width: 2,
  271. },
  272. },
  273. ],
  274. },
  275. },
  276. ],
  277. });
  278. const chartsOption2 = ref({
  279. title: [
  280. // {
  281. // text: `R=${showData.value.rangeAvg ? showData.value.rangeAvg : "-"}`,
  282. // right: "5%",
  283. // top: "42%",
  284. // textStyle: {
  285. // fontSize: 15,
  286. // color: "#333",
  287. // fontWeight: 100,
  288. // },
  289. // },
  290. {
  291. text: "极",
  292. left: "4%",
  293. top: "42%",
  294. },
  295. {
  296. text: "值",
  297. left: "4%",
  298. top: "49%",
  299. },
  300. ],
  301. toolbox: {
  302. feature: {
  303. saveAsImage: {},
  304. },
  305. },
  306. grid: {
  307. right: "15%",
  308. },
  309. xAxis: [
  310. {
  311. type: "category",
  312. boundaryGap: false,
  313. data: [],
  314. },
  315. ],
  316. yAxis: [
  317. {
  318. type: "value",
  319. },
  320. ],
  321. tooltip: {
  322. show: true,
  323. },
  324. series: [
  325. {
  326. type: "line",
  327. lineStyle: {
  328. color: "rgb(26, 122, 240)",
  329. },
  330. symbolSize: 13,
  331. symbol: "circle",
  332. itemStyle: {
  333. color: (params) => {
  334. const range = JSON.parse(value.value);
  335. const paramValue = Number(params.value);
  336. if (
  337. paramValue <= Number(range.rangeMax) &&
  338. paramValue >= Number(range.rangeMin)
  339. ) {
  340. return "rgb(26, 122, 240)";
  341. } else {
  342. return "red";
  343. }
  344. },
  345. },
  346. markLine: {
  347. silent: true,
  348. data: [
  349. {
  350. silent: false,
  351. yAxis: 0,
  352. label: {
  353. position: "end",
  354. formatter: `上限=${JSON.parse(value.value).rangeMax ? JSON.parse(value.value).rangeMax : "-"}`,
  355. color: "#333",
  356. },
  357. lineStyle: { type: "solid", color: "#333", width: 2 },
  358. },
  359. {
  360. silent: false,
  361. yAxis: 0,
  362. label: {
  363. position: "end",
  364. formatter: `下限=${JSON.parse(value.value).rangeMin ? JSON.parse(value.value).rangeMin : "-"}`,
  365. color: "#333",
  366. },
  367. lineStyle: { type: "solid", color: "#333", width: 2 },
  368. },
  369. {
  370. yAxis: 0,
  371. silent: false,
  372. label: {
  373. position: "end",
  374. formatter: ``,
  375. color: "#333",
  376. },
  377. lineStyle: {
  378. type: "solid",
  379. color: "#333",
  380. width: 2,
  381. },
  382. },
  383. ],
  384. },
  385. },
  386. ],
  387. });
  388. const Height = ref(0);
  389. const setHeight = () => {
  390. Height.value = document.querySelector(".databox").clientHeight;
  391. maxHeight.value = document.querySelector(".info").clientHeight;
  392. maxWidth.value = document.querySelector(".info").clientWidth;
  393. };
  394. const Y2value = ref([]);
  395. const X2array = ref([]);
  396. const setY2value = () => {
  397. Y2value.value = [];
  398. tableData.value.forEach((item) => {
  399. Y2value.value.push(item.range);
  400. });
  401. Y2value.value.unshift("");
  402. Y2value.value.push("");
  403. chartsOption2.value.series[0].data = Y2value.value;
  404. };
  405. const setX2array = () => {
  406. X2array.value = [];
  407. tableData.value.forEach((item, index) => {
  408. X2array.value.push(index + 1);
  409. });
  410. X2array.value.unshift("");
  411. X2array.value.push("");
  412. chartsOption2.value.xAxis[0].data = X2array.value;
  413. };
  414. const setView = () => {
  415. setHeight();
  416. charts1.value = echarts.init(document.getElementById("charts"));
  417. charts2.value = echarts.init(document.getElementById("charts1"));
  418. charts1.value.setOption(chartsOption1.value, true);
  419. charts2.value.setOption(chartsOption2.value, true);
  420. };
  421. onMounted(() => {
  422. init();
  423. });
  424. const init = (data) => {
  425. tableData.value = data;
  426. changeSelect();
  427. setHeight();
  428. nextTick(() => {
  429. charts1.value = echarts.init(document.getElementById("charts"));
  430. charts2.value = echarts.init(document.getElementById("charts1"));
  431. charts1.value.setOption(chartsOption1.value, true);
  432. charts2.value.setOption(chartsOption2.value, true);
  433. });
  434. window.addEventListener("resize", setView);
  435. };
  436. onBeforeUnmount(() => {
  437. window.removeEventListener("resize", setView);
  438. });
  439. // 暴露 init 方法
  440. defineExpose({
  441. init,
  442. });
  443. </script>
  444. <style lang="scss" scoped>
  445. @media print {
  446. #print {
  447. margin-left: -18%;
  448. }
  449. }
  450. .formStyle {
  451. width: 400px;
  452. margin: 20px auto;
  453. }
  454. .container1 {
  455. width: 100%;
  456. height: 100%;
  457. display: flex;
  458. background-color: white;
  459. .infobox {
  460. width: 200px;
  461. .header {
  462. height: 120px;
  463. border-bottom: 2px solid #00000010;
  464. padding: 20px;
  465. }
  466. .body {
  467. padding: 20px;
  468. }
  469. }
  470. .databox {
  471. flex: 1;
  472. border-left: 2px solid #00000010;
  473. .box {
  474. height: 710px;
  475. padding: 5px 20px;
  476. display: flex;
  477. flex-direction: column;
  478. .illustrate {
  479. padding: 20px 60px;
  480. }
  481. .tableTitle {
  482. text-align: center;
  483. margin: 10px 0;
  484. padding-right: 40px;
  485. }
  486. .header {
  487. margin-top: 20px;
  488. //margin-left: 100px;
  489. display: flex;
  490. width: 100%;
  491. height: auto;
  492. }
  493. //.title {
  494. // height: 50px;
  495. // display: flex;
  496. // align-items: center;
  497. // margin-bottom: 10px;
  498. // justify-content: space-between;
  499. // .btns {
  500. // display: flex;
  501. // align-items: center;
  502. // .btn {
  503. // height: 24px;
  504. // font-size: 14px;
  505. // margin: 0 5px;
  506. // }
  507. // }
  508. //}
  509. .info {
  510. margin-top: 20px;
  511. flex: 1;
  512. height: 300px;
  513. }
  514. }
  515. }
  516. }
  517. </style>