Ligature.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <template>
  2. <div class="JoinLine">
  3. <div id="container" class="container">
  4. <div class="left">
  5. <ul>
  6. <div>{{ curQue.conTitle }}</div>
  7. <li
  8. :class="'left' + index + number"
  9. v-for="(item, index) in curQue.con"
  10. :key="'left' + index"
  11. >
  12. <!-- :style="{
  13. background:
  14. JSON.stringify(data).indexOf(item.nodeId) != -1
  15. ? '#F0F0F0'
  16. : '',
  17. }" -->
  18. <div>
  19. <img
  20. v-if="item.img_list.length > 0"
  21. :src="item.img_list[0].id"
  22. alt=""
  23. @load="conImageload"
  24. />
  25. <div
  26. class="text"
  27. :class="'left' + index"
  28. v-if="item.detail.wordsList.length > 0 || item.detail.sentence"
  29. >
  30. <!-- 大于0就说明分词了 -->
  31. <template v-if="item.detail.wordsList.length > 0">
  32. <div
  33. v-for="(it, wordIndex) in item.detail.wordsList"
  34. :key="'word' + wordIndex"
  35. >
  36. <template v-if="item.detail.pyPosition == 'top'">
  37. <p
  38. style="
  39. font-family: 'GB-PINYINOK-B';
  40. font-size: 14px;
  41. line-height: 20px;
  42. "
  43. >
  44. {{ it.pinyin }}
  45. </p>
  46. <p
  47. style="
  48. font-family: 'FZJCGFKTK';
  49. font-size: 20px;
  50. line-height: 150%;
  51. "
  52. >
  53. {{ it.chs }}
  54. </p>
  55. </template>
  56. <template v-else>
  57. <p
  58. style="
  59. font-family: 'FZJCGFKTK';
  60. font-size: 20px;
  61. line-height: 150%;
  62. "
  63. >
  64. {{ it.chs }}
  65. </p>
  66. <p
  67. style="
  68. font-family: 'GB-PINYINOK-B';
  69. font-size: 14px;
  70. line-height: 20px;
  71. "
  72. >
  73. {{ it.pinyin }}
  74. </p>
  75. </template>
  76. </div>
  77. </template>
  78. <template v-else>
  79. {{ item.detail.sentence }}
  80. </template>
  81. </div>
  82. </div>
  83. <span>{{ item.Number }}</span>
  84. <img
  85. v-if="JSON.stringify(data).indexOf(item.nodeId) == -1"
  86. name="source"
  87. :id="item.nodeId"
  88. src="../../../assets/adult/LineImg.png"
  89. alt=""
  90. />
  91. <img
  92. v-else
  93. :id="item.nodeId"
  94. name="target"
  95. src="../../../assets/adult/LineImg-select.png"
  96. alt=""
  97. />
  98. </li>
  99. </ul>
  100. </div>
  101. <div class="right">
  102. <ul>
  103. <div>{{ curQue.optionTitle }}</div>
  104. <li
  105. :class="'right' + index + number"
  106. v-for="(item, index) in curQue.option"
  107. :key="'right' + index"
  108. >
  109. <!-- :style="{
  110. background:
  111. JSON.stringify(data).indexOf(item.nodeId) != -1
  112. ? '#F0F0F0'
  113. : '',
  114. }" -->
  115. <img
  116. v-if="JSON.stringify(data).indexOf(item.nodeId) == -1"
  117. name="source"
  118. :id="item.nodeId"
  119. src="../../../assets/adult/LineImg.png"
  120. alt=""
  121. />
  122. <img
  123. v-else
  124. :id="item.nodeId"
  125. name="target"
  126. src="../../../assets/adult/LineImg-select.png"
  127. alt=""
  128. />
  129. <span>{{ item.Number }}</span>
  130. <div>
  131. <img
  132. v-if="item.img_list.length > 0"
  133. :src="item.img_list[0].id"
  134. alt=""
  135. @load="conImageload"
  136. />
  137. <div
  138. class="text"
  139. :class="'right' + index"
  140. v-if="item.detail.wordsList.length > 0 || item.detail.sentence"
  141. >
  142. <!-- 大于0就说明分词了 -->
  143. <template v-if="item.detail.wordsList.length > 0">
  144. <div
  145. v-for="(it, wordIndex) in item.detail.wordsList"
  146. :key="'word' + wordIndex"
  147. >
  148. <template v-if="item.detail.pyPosition == 'top'">
  149. <p
  150. style="
  151. font-family: 'GB-PINYINOK-B';
  152. font-size: 14px;
  153. line-height: 20px;
  154. "
  155. >
  156. {{ it.pinyin }}
  157. </p>
  158. <p
  159. style="
  160. font-family: 'FZJCGFKTK';
  161. font-size: 20px;
  162. line-height: 150%;
  163. "
  164. >
  165. {{ it.chs }}
  166. </p>
  167. </template>
  168. <template v-else>
  169. <p
  170. style="
  171. font-family: 'FZJCGFKTK';
  172. font-size: 20px;
  173. line-height: 150%;
  174. "
  175. >
  176. {{ it.chs }}
  177. </p>
  178. <p
  179. style="
  180. font-family: 'GB-PINYINOK-B';
  181. font-size: 14px;
  182. line-height: 20px;
  183. "
  184. >
  185. {{ it.pinyin }}
  186. </p>
  187. </template>
  188. </div>
  189. </template>
  190. <template v-else>
  191. {{ item.detail.sentence }}
  192. </template>
  193. </div>
  194. </div>
  195. </li>
  196. </ul>
  197. </div>
  198. </div>
  199. <!-- 清除所有连线及连线的状态 -->
  200. <div class="fuwei" :class="[TaskModel == 'ANSWER' ? 'notAllow' : '']">
  201. <div @click="clearLine">
  202. <img src="../../../assets/adult/fuwei.png" alt="" />
  203. 复位
  204. </div>
  205. </div>
  206. </div>
  207. </template>
  208. <script>
  209. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  210. //例如:import 《组件名称》from ‘《组件路径》';
  211. export default {
  212. //import引入的组件需要注入到对象中才能使用
  213. components: {},
  214. props: ["curQue", "TaskModel", "number"],
  215. data() {
  216. //这里存放数据
  217. return {
  218. data: [],
  219. leftList: [
  220. {
  221. text: "Arrive at the airport ahead of time ______",
  222. nodeId: "left_1"
  223. },
  224. {
  225. text: "Arrive at the airport ahead of time ______",
  226. nodeId: "left_2"
  227. },
  228. {
  229. text: "Arrive at the airport ahead of time ______",
  230. nodeId: "left_3"
  231. },
  232. {
  233. text: "Arrive at the airport ahead of time ______",
  234. nodeId: "left_4"
  235. },
  236. {
  237. text: "Arrive at the airport ahead of time ______",
  238. nodeId: "left_5"
  239. },
  240. {
  241. text: "Arrive at the airport ahead of time ______",
  242. nodeId: "left_6"
  243. },
  244. {
  245. text: "Arrive at the airport ahead of time ______",
  246. nodeId: "left_7"
  247. }
  248. ],
  249. rightList: [
  250. { text: "把来访者直接送到宾馆", en: "a", nodeId: "right_1" },
  251. { text: "把来访者直接送到宾馆", en: "b", nodeId: "right_2" },
  252. { text: "把来访者直接送到宾馆", en: "c", nodeId: "right_3" },
  253. { text: "把来访者直接送到宾馆", en: "d", nodeId: "right_4" },
  254. { text: "把来访者直接送到宾馆", en: "e", nodeId: "right_5" },
  255. { text: "把来访者直接送到宾馆", en: "f", nodeId: "right_6" },
  256. { text: "把来访者直接送到宾馆", en: "g", nodeId: "right_7" }
  257. ],
  258. allimgnumber: 0,
  259. lodimgnumber: 0
  260. };
  261. },
  262. //计算属性 类似于data概念
  263. computed: {},
  264. //监控data中数据变化
  265. watch: {
  266. curQue(val, oldval) {
  267. this.$forceUpdate(); //触发更新函数更新高度
  268. }
  269. },
  270. //方法集合
  271. methods: {
  272. // 清除所有连线
  273. clearLine() {
  274. if (!this.TaskModel || this.TaskModel != "ANSWER") {
  275. this.jsPlumb.deleteEveryConnection(); //清除连线方法
  276. this.data = [];
  277. sessionStorage.removeItem("LineData");
  278. }
  279. },
  280. showPlumb() {
  281. this.jsPlumb = this.$jsPlumb.getInstance({
  282. Container: "container", // 选择器id
  283. EndpointStyle: { radius: 1, fill: "#74B5CA" }, // 端点样式
  284. PaintStyle: { stroke: "#DE4444", strokeWidth: 2 }, // 绘画样式,默认8px线宽 #456
  285. HoverPaintStyle: { stroke: "#18A0FB", strokeWidth: null }, // 默认悬停样式 默认为null
  286. ConnectionOverlays: [
  287. // // 此处可以设置所有箭头的样式
  288. // [
  289. // "Arrow",
  290. // {
  291. // // 设置参数可以参考中文文档
  292. // location: 1,
  293. // length: 12,
  294. // paintStyle: {
  295. // stroke: "#7663EC",
  296. // fill: "#7663EC",
  297. // },
  298. // },
  299. // ],
  300. // [
  301. // "Label",
  302. // {
  303. // location: 0.1,
  304. // cssClass: "aLabel", //hover时label的样式名
  305. // events: {
  306. // click: (info) => {
  307. // console.log(info);
  308. // },
  309. // },
  310. // visible: true,
  311. // },
  312. // ],
  313. ],
  314. Connector: ["Straight"], // 要使用的默认连接器的类型:直线,折线,曲线等
  315. DrapOptions: { cursor: "crosshair", zIndex: 2000 }
  316. });
  317. this.jsPlumb.batch(() => {
  318. for (let i = 0; i < this.curQue.con.length; i++) {
  319. this.initLeaf(this.curQue.con[i].nodeId, "source");
  320. }
  321. for (let j = 0; j < this.curQue.option.length; j++) {
  322. this.initLeaf(this.curQue.option[j].nodeId, "target");
  323. }
  324. });
  325. this.setjsPlumb(true, true);
  326. //点击连线
  327. this.jsPlumb.bind("click", (conn, originalEvent) => {
  328. if (!this.TaskModel || this.TaskModel != "ANSWER") {
  329. // 删除点击的线
  330. this.data.forEach((item, i) => {
  331. if (item.source == conn.sourceId) {
  332. this.data.splice(i, 1);
  333. }
  334. });
  335. let node = document.getElementById(conn.sourceId);
  336. this.jsPlumb.removeAllEndpoints(node);
  337. sessionStorage.setItem("LineData", JSON.stringify(this.data));
  338. this.$set(this.curQue, "Bookanswer", JSON.stringify(this.data));
  339. }
  340. });
  341. //连线时触发
  342. this.jsPlumb.bind("connection", (conn, originalEvent) => {
  343. if (!this.TaskModel || this.TaskModel != "ANSWER") {
  344. let fig = false;
  345. this.data.forEach(item => {
  346. if (item.source == conn.sourceId && item.target == conn.targetId) {
  347. fig = true;
  348. }
  349. });
  350. if (!fig) {
  351. this.data.push({
  352. source: conn.sourceId,
  353. target: conn.targetId
  354. });
  355. sessionStorage.setItem("LineData", JSON.stringify(this.data));
  356. this.$set(this.curQue, "Bookanswer", JSON.stringify(this.data));
  357. }
  358. }
  359. });
  360. //右键触发
  361. this.jsPlumb.bind("contextmenu", (conn, originalEvent) => {
  362. console.log(conn, originalEvent);
  363. });
  364. },
  365. // 初始化规则使其可以连线、拖拽
  366. initLeaf(id, type) {
  367. const ins = this.jsPlumb;
  368. const elem = document.getElementById(id);
  369. if (type === "source") {
  370. ins.makeSource(elem, {
  371. anchor: [1, 0.5, 0.5, 0.5], // 左 上 右 下 数字我调不太准确 可改成left right
  372. allowLoopback: false, //允许回连
  373. maxConnections: 1 //最大连接数(-1表示不限制)
  374. });
  375. } else {
  376. ins.makeTarget(elem, {
  377. anchor: [0, 0.5, 0, 0],
  378. allowLoopback: false,
  379. maxConnections: 1
  380. });
  381. }
  382. },
  383. setjsPlumb(sourceFlag, targetFlag) {
  384. const source = document.getElementsByName("source");
  385. const target = document.getElementsByName("target");
  386. this.jsPlumb.setSourceEnabled(source, sourceFlag);
  387. this.jsPlumb.setTargetEnabled(target, targetFlag);
  388. this.jsPlumb.setDraggable(source, false); // 是否支持拖拽
  389. this.jsPlumb.setDraggable(target, false); // 是否支持拖拽
  390. },
  391. conImageload() {
  392. this.lodimgnumber++;
  393. let _this = this;
  394. if (_this.lodimgnumber == _this.allimgnumber) {
  395. _this.curQue.option.forEach((item, index) => {
  396. for (let i = 0; i < this.curQue.con.length; i++) {
  397. let nodeleft = document.getElementsByClassName(
  398. `left${i + this.number}`
  399. )[0];
  400. let noderight = document.getElementsByClassName(
  401. `right${index + this.number}`
  402. )[0];
  403. if (nodeleft.offsetHeight > noderight.offsetHeight) {
  404. noderight.style.height = nodeleft.offsetHeight + "px";
  405. } else {
  406. nodeleft.style.height = noderight.offsetHeight + "px";
  407. }
  408. }
  409. });
  410. }
  411. }
  412. },
  413. //生命周期 - 创建完成(可以访问当前this实例)
  414. created() {
  415. let sData = null;
  416. if (!this.curQue.Bookanswer) {
  417. // sData = JSON.parse(sessionStorage.getItem("LineData"));
  418. sData = [];
  419. } else {
  420. sData = JSON.parse(this.curQue.Bookanswer);
  421. }
  422. this.data = [];
  423. if (sData) {
  424. this.data = sData;
  425. }
  426. this.curQue.con.forEach((item, i) => {
  427. item.nodeId = "left_" + i;
  428. if (item.img_list.length > 0) {
  429. this.allimgnumber++;
  430. }
  431. });
  432. this.curQue.option.forEach((item, i) => {
  433. item.nodeId = "right_" + i;
  434. if (item.img_list.length > 0) {
  435. this.allimgnumber++;
  436. }
  437. });
  438. },
  439. //生命周期 - 挂载完成(可以访问DOM元素)
  440. mounted() {
  441. this.showPlumb();
  442. // 根据记录自动连起来
  443. if (this.allimgnumber == 0) {
  444. for (let i = 0; i < this.curQue.con.length; i++) {
  445. let nodeleft = document.getElementsByClassName(`left${i}`)[0];
  446. let noderight = document.getElementsByClassName(`right${i}`)[0];
  447. if (nodeleft && noderight) {
  448. console.log(nodeleft);
  449. console.log(noderight);
  450. if (nodeleft.offsetHeight > noderight.offsetHeight) {
  451. noderight.style.height = nodeleft.offsetHeight + "px";
  452. } else {
  453. nodeleft.style.height = noderight.offsetHeight + "px";
  454. }
  455. }
  456. }
  457. }
  458. setTimeout(() => {
  459. if (this.data.length > 0) {
  460. console.log(this.data);
  461. this.data.forEach(item => {
  462. this.jsPlumb.connect({
  463. source: item.source,
  464. target: item.target
  465. });
  466. });
  467. }
  468. }, 1000);
  469. },
  470. //生命周期-创建之前
  471. beforeCreated() {},
  472. //生命周期-挂载之前
  473. beforeMount() {},
  474. //生命周期-更新之前
  475. beforUpdate() {},
  476. //生命周期-更新之后
  477. updated() {
  478. for (let i = 0; i < this.curQue.con.length; i++) {
  479. let nodeleft = document.getElementsByClassName(`left${i}`)[0];
  480. let noderight = document.getElementsByClassName(`right${i}`)[0];
  481. if (nodeleft && noderight) {
  482. if (nodeleft.offsetHeight > noderight.offsetHeight) {
  483. noderight.style.height = nodeleft.offsetHeight + "px";
  484. } else {
  485. nodeleft.style.height = noderight.offsetHeight + "px";
  486. }
  487. }
  488. }
  489. },
  490. //生命周期-销毁之前
  491. beforeDestory() {},
  492. //生命周期-销毁完成
  493. destoryed() {},
  494. //如果页面有keep-alive缓存功能,这个函数会触发
  495. activated() {}
  496. };
  497. </script>
  498. <style lang="scss" scoped>
  499. /* @import url(); 引入css类 */
  500. .JoinLine {
  501. width: 100%;
  502. .container {
  503. background: #f7f7f7;
  504. border: 1px solid rgba(0, 0, 0, 0.1);
  505. box-sizing: border-box;
  506. border-radius: 8px;
  507. position: relative;
  508. display: flex;
  509. justify-content: center;
  510. padding: 24px 40px;
  511. ul {
  512. list-style: none;
  513. li {
  514. // width: 333px;
  515. // // height: 64px;
  516. // background: #ffffff;
  517. // border: 1px solid rgba(0, 0, 0, 0.1);
  518. // box-sizing: border-box;
  519. // border-radius: 8px;
  520. margin-bottom: 16px;
  521. display: flex;
  522. align-items: center;
  523. > img {
  524. width: 24px;
  525. height: 24px;
  526. }
  527. }
  528. }
  529. .left {
  530. width: 50%;
  531. ul {
  532. > div {
  533. text-align: center;
  534. font-weight: bold;
  535. font-size: 16px;
  536. line-height: 150%;
  537. color: #000000;
  538. margin-bottom: 16px;
  539. }
  540. li {
  541. padding: 8px 0;
  542. display: flex;
  543. justify-content: flex-end; //右对齐
  544. > div {
  545. font-size: 16px;
  546. line-height: 150%;
  547. color: #000000;
  548. img {
  549. max-width: 238px;
  550. height: 158px;
  551. }
  552. .text {
  553. max-width: 200px;
  554. width: 100%;
  555. padding: 8px 16px;
  556. background: #ffffff;
  557. border: 1px solid rgba(0, 0, 0, 0.1);
  558. box-sizing: border-box;
  559. border-radius: 8px;
  560. display: flex;
  561. flex-wrap: wrap;
  562. p {
  563. margin: 0;
  564. }
  565. }
  566. }
  567. span {
  568. width: 24px;
  569. height: 24px;
  570. font-family: "robot";
  571. font-style: normal;
  572. font-weight: normal;
  573. font-size: 16px;
  574. line-height: 150%;
  575. text-align: center;
  576. color: #ffffff;
  577. background: #a7a7a7;
  578. border-radius: 50%;
  579. margin-left: 8px;
  580. margin-right: 12px;
  581. }
  582. > img {
  583. cursor: pointer;
  584. width: 24px;
  585. height: 24px;
  586. }
  587. }
  588. }
  589. }
  590. .right {
  591. width: 50%;
  592. margin-left: 88px;
  593. ul {
  594. > div {
  595. width: 334px;
  596. text-align: center;
  597. font-weight: bold;
  598. font-size: 16px;
  599. line-height: 150%;
  600. color: #000000;
  601. margin-bottom: 16px;
  602. }
  603. li {
  604. padding: 8px 0;
  605. > img {
  606. margin-left: 16px;
  607. width: 24px;
  608. height: 24px;
  609. }
  610. > span {
  611. width: 24px;
  612. height: 24px;
  613. font-family: "robot";
  614. font-style: normal;
  615. font-weight: normal;
  616. font-size: 16px;
  617. line-height: 150%;
  618. text-align: center;
  619. color: #ffffff;
  620. background: #a7a7a7;
  621. border-radius: 50%;
  622. margin-left: 12px;
  623. margin-right: 8px;
  624. }
  625. div {
  626. img {
  627. max-width: 238px;
  628. height: 158px;
  629. }
  630. .text {
  631. max-width: 200px;
  632. padding: 8px 16px;
  633. background: #ffffff;
  634. border: 1px solid rgba(0, 0, 0, 0.1);
  635. box-sizing: border-box;
  636. border-radius: 8px;
  637. display: flex;
  638. align-items: center;
  639. flex-wrap: wrap;
  640. p {
  641. margin: 0;
  642. }
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. .fuwei {
  650. margin-top: 16px;
  651. height: 40px;
  652. &.notAllow {
  653. > div {
  654. cursor: not-allowed;
  655. }
  656. }
  657. > div {
  658. float: right;
  659. width: 72px;
  660. height: 40px;
  661. background: #ffffff;
  662. border: 1px solid rgba(0, 0, 0, 0.1);
  663. box-sizing: border-box;
  664. border-radius: 8px;
  665. display: flex;
  666. align-items: center;
  667. font-weight: bold;
  668. font-size: 16px;
  669. line-height: 150%;
  670. display: flex;
  671. align-items: center;
  672. text-align: center;
  673. color: #000000;
  674. cursor: pointer;
  675. img {
  676. margin-left: 8px;
  677. width: 24px;
  678. height: 24px;
  679. }
  680. }
  681. }
  682. }
  683. </style>
  684. <style lang="scss">
  685. .jtk-connector {
  686. path {
  687. cursor: pointer;
  688. }
  689. }
  690. </style>