EditPanel.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. <template>
  2. <transition
  3. appear
  4. name="custom-classes-transition"
  5. enter-active-class="animated slideInRight speed"
  6. leave-active-class="animated slideOutRight speed"
  7. >
  8. <div class="hots-panel" v-show="show">
  9. <div class="ui-between header">
  10. <span>{{ editTitle }}{{ $i18n.t("hotspot.hotspot_name") }}</span>
  11. <i class="iconfont icon_close" @click="realCancel"></i>
  12. </div>
  13. <div class="content" ref="content">
  14. <div class="type-setting">
  15. <div class="remark">{{ $i18n.t("hotspot.hotspot_type") }}</div>
  16. <combox
  17. class="combox"
  18. :data="hotspotTypeList"
  19. :selected-id="hotspot.hotspotType"
  20. @change="onHotSpotTypeChange"
  21. />
  22. </div>
  23. <div class="icon-setting">
  24. <div class="remark">{{ $i18n.t("hotspot.hotspot_icon") }}</div>
  25. <combox
  26. class="combox"
  27. :data="hotspotIconTypeList"
  28. :selected-id="hotspot.hotspotIconType"
  29. @change="onHotspotIconTypeChange"
  30. />
  31. <component
  32. class="icon-setting-component"
  33. :is="iconTypeComponent"
  34. ref="icon-setting-component"
  35. />
  36. <div
  37. class="bars"
  38. v-if="hotspot.hotspotIconType !== 'personalized_tag'"
  39. >
  40. <RangeItem :value="rang" @input="onRangeChange" />
  41. </div>
  42. </div>
  43. <div
  44. class="title-setting"
  45. v-if="hotspot.hotspotIconType !== 'personalized_tag'"
  46. >
  47. <div class="remark-highlight">
  48. {{ $i18n.t("hotspot.hotspot_title") }}
  49. </div>
  50. <div class="title-input-wrapper">
  51. <input
  52. v-model.trim="hotspot.hotspotTitle"
  53. type="text"
  54. maxlength="50"
  55. :placeholder="$i18n.t('hotspot.title_placeholder')"
  56. />
  57. <span class="count">{{ hotspot.hotspotTitle.length }}/50</span>
  58. </div>
  59. <div class="remark">
  60. {{ $i18n.t("hotspot.title_show_mode") }}
  61. </div>
  62. <TabbarSwitcher
  63. class="display-mode-selector"
  64. :tabList="[
  65. // $i18n.t('hotspot.show_on_hover'),
  66. $i18n.t('hotspot.always_show'),
  67. $i18n.t('hotspot.never_show'),
  68. ]"
  69. :activeIdx="currentTitleDispayModeIdx"
  70. @select="onSelectTitleDisplayMode"
  71. />
  72. <div class="remark">
  73. {{ $i18n.t("hotspot.title_position") }}
  74. </div>
  75. <TabbarSwitcherIcon
  76. class="display-mode-selector"
  77. :tabList="[
  78. {
  79. icon: 'icon-up',
  80. tip: $i18n.t('hotspot.title_top'),
  81. },
  82. {
  83. icon: 'icon-down',
  84. tip: $i18n.t('hotspot.title_bottom'),
  85. },
  86. {
  87. icon: 'icon-left',
  88. tip: $i18n.t('hotspot.title_left'),
  89. },
  90. {
  91. icon: 'icon-right',
  92. tip: $i18n.t('hotspot.title_right'),
  93. },
  94. // {
  95. // icon: 'icon-mobile',
  96. // tip: $i18n.t('hotspot.title_custom'),
  97. // },
  98. ]"
  99. :activeIdx="currentTitlePositionIdx"
  100. @select="onSelectTitlePosition"
  101. />
  102. </div>
  103. <div class="effect-setting">
  104. <div class="title-line">
  105. <div
  106. class="remark-highlight"
  107. v-if="
  108. $i18n.t(
  109. `hotspot.hotspot_type_specific_settings_title.${hotspot.hotspotType}`
  110. )
  111. "
  112. >
  113. {{
  114. $i18n.t(
  115. `hotspot.hotspot_type_specific_settings_title.${hotspot.hotspotType}`
  116. )
  117. }}
  118. </div>
  119. <div class="tip" v-if="currentHotspotTypeConfigData.tip">
  120. {{ currentHotspotTypeConfigData.tip }}
  121. </div>
  122. </div>
  123. <component
  124. class="effect-setting-component"
  125. @sceneSelect="handleSceneSelect"
  126. :scene="hotspot.secne"
  127. @imageChange="
  128. (data) => {
  129. hotspot.image = data;
  130. }
  131. "
  132. :image="hotspot.image"
  133. @linkChange="
  134. (data) => {
  135. hotspot.hyperlink = data;
  136. }
  137. "
  138. :link="hotspot.hyperlink"
  139. @linkOpenType="
  140. (data) => {
  141. hotspot.linkOpenType = data;
  142. }
  143. "
  144. :linkOpenType="hotspot.linkOpenType"
  145. @textChange="
  146. (data) => {
  147. hotspot.textarea = data;
  148. }
  149. "
  150. :textarea="hotspot.textarea"
  151. @audioChange="
  152. (data) => {
  153. hotspot.audio = data;
  154. }
  155. "
  156. :audio="hotspot.audio"
  157. @videoChange="
  158. (data) => {
  159. hotspot.video = data;
  160. }
  161. "
  162. :video="hotspot.video"
  163. :is="effectSettingComponent"
  164. />
  165. </div>
  166. </div>
  167. <div class="ui-between footer" app-border dir-top>
  168. <button
  169. class="ui-button deepcancel"
  170. :class="{ disable: false }"
  171. @click="cancel"
  172. >
  173. {{ $i18n.t("hotspot.cancel") }}
  174. </button>
  175. <button
  176. class="ui-button submit"
  177. :class="{ disable: !canSubmit }"
  178. @click="save"
  179. >
  180. {{ $i18n.t("hotspot.finish") }}
  181. </button>
  182. </div>
  183. </div>
  184. </transition>
  185. </template>
  186. <script>
  187. import RangeItem from "@/components/rangeItem/index.vue";
  188. import Combox from "@/components/shared/Combox";
  189. import { mapGetters } from "vuex";
  190. import Switcher from "@/components/shared/Switcher.vue";
  191. import TabbarSwitcher from "@/components/shared/TabbarSwitcher.vue";
  192. import TabbarSwitcherIcon from "@/components/shared/TabbarSwitcherIcon.vue";
  193. import hotspotTypeList from "./hotspotTypeList.js";
  194. import { isValidPhoneNumber } from "libphonenumber-js/max";
  195. export default {
  196. props: ["show", "data", "editTitle"],
  197. components: {
  198. RangeItem,
  199. Combox,
  200. Switcher,
  201. TabbarSwitcher,
  202. TabbarSwitcherIcon,
  203. },
  204. data() {
  205. return {
  206. hotspotTypeList,
  207. hotspotIconTypeList: [
  208. {
  209. name: this.$i18n.t("hotspot.hotspot_icon_type.system_icon"),
  210. id: "system_icon",
  211. },
  212. {
  213. name: this.$i18n.t("hotspot.hotspot_icon_type.custom_image"),
  214. id: "custom_image",
  215. },
  216. {
  217. name: this.$i18n.t("hotspot.hotspot_icon_type.serial_frame"),
  218. id: "serial_frame",
  219. },
  220. {
  221. name: this.$i18n.t("hotspot.hotspot_icon_type.personalized_tag"),
  222. id: "personalized_tag",
  223. },
  224. ],
  225. rang: {
  226. label: this.$i18n.t("hotspot.icon_size"),
  227. unit: this.$i18n.t("hotspot.unit"),
  228. gradient: 0.1,
  229. value: 1,
  230. min: 0.5,
  231. max: 2,
  232. },
  233. };
  234. },
  235. watch: {
  236. "hotspot.fontSize": {
  237. handler(val) {
  238. const rangeValue = val / 12;
  239. // console.log("rangeValue", rangeValue);
  240. this.rang.value = rangeValue.toFixed(1);
  241. },
  242. immediate: true,
  243. },
  244. hotspot: {
  245. handler(val) {
  246. console.warn("hotspot", val);
  247. this.$bus.emit("edithotspot", val);
  248. },
  249. deep: true,
  250. },
  251. // hotspotIcon: {
  252. // handler(val) {
  253. // console.error("this.hotspotIcon", val);
  254. // val.img.length > 0 &&
  255. // this.$getKrpano().set(`hotspot[${this.hotspot.name}].url`, val.img);
  256. // },
  257. // deep: true,
  258. // },
  259. // "hotspot.img": function () {
  260. // console.log("this.hotspot.img", this.hotspot.img);
  261. // this.$getKrpano().set(
  262. // `hotspot[${this.hotspot.name}].url`,
  263. // this.hotspot.img
  264. // );
  265. // },
  266. // "hotspot.titlePosition": function (val) {
  267. // console.log("111", val);
  268. // if (val === "bottom") {
  269. // this.$getKrpano().set("layer[tooltip_" + this.hotspot.name + "].css");
  270. // }
  271. // },
  272. // "hotspot.hotspotTitle": function () {
  273. // this.$getKrpano().set(
  274. // "layer[tooltip_" + this.hotspot.name + "].html",
  275. // `<span style="color:white">${this.hotspot.hotspotTitle}</span>`
  276. // );
  277. // },
  278. // 'hotspot.visible': function () {
  279. // this.$getKrpano().set('layer[tooltip_' + this.hotspot.name + '].visible', this.hotspot.visible)
  280. // },
  281. // "hotspot.size": {
  282. // immediate: true,
  283. // handler: function (newVal) {
  284. // let h = 52;
  285. // let scaleH = h * newVal;
  286. // let offset = "-130%";
  287. // this.rang = { ...this.rang, value: newVal };
  288. // this.$getKrpano().set(`hotspot[${this.hotspot.name}].height`, scaleH);
  289. // if (newVal < 1) {
  290. // offset = "-200%";
  291. // }
  292. // if (newVal > 1) {
  293. // offset = "-100%";
  294. // }
  295. // this.$getKrpano().set(
  296. // "layer[tooltip_" + this.hotspot.name + "].y",
  297. // `${offset}`
  298. // );
  299. // },
  300. // },
  301. // "hotspot.fontSize": {
  302. // handler: function (newVal) {
  303. // this.$getKrpano().set(
  304. // "layer[tooltip_" + this.hotspot.name + "].css",
  305. // `text-align:center; color:#FFFFFF;
  306. // font-family:STXihei;font-size:${newVal}px;`
  307. // );
  308. // },
  309. // },
  310. },
  311. computed: {
  312. ...mapGetters({
  313. hotspot: "hotspot",
  314. backupHotSpot: "backupHotSpot",
  315. hotspotIcon: "hotspotIcon",
  316. }),
  317. iconTypeComponent() {
  318. let tmp = this.hotspot.hotspotIconType;
  319. return () => import(`./hotspotIconType/${tmp}.vue`);
  320. },
  321. currentTitleDispayModeIdx() {
  322. switch (this.hotspot.titleDisplayMode) {
  323. // case "hover":
  324. // return 0;
  325. case "always":
  326. return 0;
  327. case "never":
  328. return 1;
  329. default:
  330. return 0;
  331. }
  332. },
  333. currentTitlePositionIdx() {
  334. switch (this.hotspot.titlePosition) {
  335. case "top":
  336. return 0;
  337. case "bottom":
  338. return 1;
  339. case "left":
  340. return 2;
  341. case "right":
  342. return 3;
  343. case "custom":
  344. return 4;
  345. default:
  346. return 0;
  347. }
  348. },
  349. effectSettingComponent() {
  350. let tmp = this.hotspot.hotspotType;
  351. return () => import(`./hotspotType/${tmp}.vue`);
  352. },
  353. canSubmit() {
  354. // 热点类型相关设置项
  355. switch (this.hotspot.hotspotType) {
  356. case "scene":
  357. if (!(this.hotspot.secne && this.hotspot.secne.id)) {
  358. return false;
  359. }
  360. break;
  361. case "image":
  362. if (!this.hotspot.image || this.hotspot.image.length === 0) {
  363. return false;
  364. }
  365. break;
  366. case "video":
  367. if (!this.hotspot.video) {
  368. return false;
  369. }
  370. break;
  371. case "audio":
  372. if (!this.hotspot.audio) {
  373. return false;
  374. }
  375. break;
  376. case "link":
  377. if (!this.hotspot.hyperlink) {
  378. return false;
  379. }
  380. break;
  381. case "textarea":
  382. if (!this.hotspot.textarea) {
  383. return false;
  384. }
  385. break;
  386. case "tag":
  387. break;
  388. case "imageText":
  389. if (
  390. this.hotspot.imageTextInfo.imageList.length === 0 ||
  391. this.hotspot.imageTextInfo.text.length === 0
  392. ) {
  393. return false;
  394. }
  395. break;
  396. case "article":
  397. if (!this.hotspot.articleInfo.html) {
  398. return false;
  399. }
  400. break;
  401. case "pdf":
  402. if (!this.hotspot.pdfInfo.name || !this.hotspot.pdfInfo.url) {
  403. return false;
  404. }
  405. break;
  406. case "phone":
  407. if (
  408. !isValidPhoneNumber(this.hotspot.phoneInfo.phone) &&
  409. !isValidPhoneNumber("+86" + this.hotspot.phoneInfo.phone)
  410. ) {
  411. return false;
  412. }
  413. break;
  414. default:
  415. break;
  416. }
  417. // 热点图标类型相关设置项
  418. switch (this.hotspot.hotspotIconType) {
  419. case "system_icon":
  420. break;
  421. case "custom_image":
  422. if (!this.hotspot.customIconInfo.img) {
  423. return false;
  424. }
  425. break;
  426. case "serial_frame":
  427. if (
  428. !this.hotspot.serialFrameInfo.img ||
  429. this.hotspot.serialFrameInfo.img.length === 0
  430. ) {
  431. return false;
  432. }
  433. break;
  434. case "personalized_tag":
  435. if (
  436. this.hotspot.personalizedTagInfo.isTextWrap &&
  437. this.hotspot.personalizedTagInfo.textNumPerLine <= 0
  438. ) {
  439. return false;
  440. }
  441. break;
  442. default:
  443. break;
  444. }
  445. // 其他设置项
  446. if (!this.hotspot.hotspotTitle) {
  447. return false;
  448. }
  449. return true;
  450. },
  451. currentHotspotTypeConfigData() {
  452. return hotspotTypeList.find((item) => {
  453. return item.id === this.hotspot.hotspotType;
  454. });
  455. },
  456. },
  457. beforeDestroy() {
  458. this.$bus.removeListener("resethotspotTitle", this.listerFnReset);
  459. this.$bus.off("edithotspot", this.handleEditHotspot);
  460. this.$bus.off("delhotspot", this.cancel);
  461. },
  462. mounted() {
  463. this.$bus.on("resethotspotTitle", this.listerFnReset);
  464. this.$bus.on("delhotspot", this.cancel);
  465. this.$bus.on("edithotspot", this.handleEditHotspot);
  466. setTimeout(() => {
  467. if (
  468. this.editTitle != "编辑" &&
  469. this.editTitle != this.$i18n.t("hotspot.edit")
  470. ) {
  471. this.rang.value = window.g_hotspotCurrentScale;
  472. this.onRangeChange({ value: window.g_hotspotCurrentScale });
  473. }
  474. }, 300);
  475. },
  476. methods: {
  477. handleEditHotspot(data) {
  478. const krpano = document.getElementById("krpanoSWFObject");
  479. __krfn.utils.edithotspot(krpano, data);
  480. },
  481. handleSceneSelect(data) {
  482. this.hotspot.secne = {
  483. ...data,
  484. someData: {},
  485. };
  486. },
  487. onHotSpotTypeChange(data) {
  488. this.hotspot.hotspotType = data.id;
  489. },
  490. onHotspotIconTypeChange(data) {
  491. this.hotspot.hotspotIconType = data.id;
  492. },
  493. clamp(num, min, max) {
  494. return num <= min ? min : num >= max ? max : num;
  495. },
  496. onRangeChange(data) {
  497. console.log(data);
  498. this.rang = { ...this.rang, value: data.value };
  499. this.hotspot.size = data.value;
  500. const fontsize = data.value * 12;
  501. const updateSize = Math.floor(fontsize);
  502. this.hotspot.fontSize = updateSize;
  503. console.log("updateSize", updateSize);
  504. // switch (data.value) {
  505. // case 0.5:
  506. // case 0.6:
  507. // case 0.7:
  508. // this.hotspot.fontSize = 12;
  509. // break;
  510. // case 0.8:
  511. // case 0.9:
  512. // case 1.0:
  513. // case 1.1:
  514. // case 1.2:
  515. // this.hotspot.fontSize = 14;
  516. // break;
  517. // case 1.3:
  518. // case 1.4:
  519. // case 1.5:
  520. // case 1.6:
  521. // case 1.7:
  522. // this.hotspot.fontSize = 17;
  523. // break;
  524. // case 1.8:
  525. // case 1.9:
  526. // case 2:
  527. // this.hotspot.fontSize = 20;
  528. // break;
  529. // default:
  530. // break;
  531. // }
  532. },
  533. onSelectTitleDisplayMode(idx) {
  534. switch (idx) {
  535. // case 0:
  536. // this.hotspot.titleDisplayMode = "hover";
  537. // break;
  538. case 0:
  539. this.hotspot.titleDisplayMode = "always";
  540. break;
  541. case 1:
  542. this.hotspot.titleDisplayMode = "never";
  543. break;
  544. default:
  545. break;
  546. }
  547. },
  548. onSelectTitlePosition(idx) {
  549. switch (idx) {
  550. case 0:
  551. this.hotspot.titlePosition = "top";
  552. break;
  553. case 1:
  554. this.hotspot.titlePosition = "bottom";
  555. break;
  556. case 2:
  557. this.hotspot.titlePosition = "left";
  558. break;
  559. case 3:
  560. this.hotspot.titlePosition = "right";
  561. break;
  562. case 4:
  563. this.hotspot.titlePosition = "custom";
  564. break;
  565. default:
  566. break;
  567. }
  568. },
  569. listerFnReset() {
  570. if (
  571. this.hotspot.hotspotTitle == "单击确定热点位置" ||
  572. this.hotspot.hotspotTitle == this.$i18n.t("hotspot.click_to_comfirm")
  573. ) {
  574. this.hotspot.hotspotTitle = "";
  575. }
  576. },
  577. cancel() {
  578. // if (!(this.editTitle == this.$i18n.t("hotspot.edit"))) {
  579. this.$confirm({
  580. title: this.$i18n.t("tips.title"),
  581. content: this.$i18n.t("hotspot.cancel_add_hotspot"),
  582. ok: () => {
  583. this.realCancel();
  584. },
  585. });
  586. // }
  587. },
  588. realCancel() {
  589. this.$store.commit("SetHotspot", this.backupHotSpot);
  590. console.log("cancel", this.backupHotSpot);
  591. this.$getKrpano().call(
  592. "cancelJQHotspot(" + this.backupHotSpot.name + ");"
  593. );
  594. this.$emit("close", {
  595. type: this.editTitle == this.$i18n.t("hotspot.edit") ? "edit" : "add",
  596. data: this.backupHotSpot,
  597. });
  598. },
  599. reset(data) {
  600. this.$bus.emit("edithotspotTitle", data);
  601. this.$bus.emit("edithotspotTitleisShow", data);
  602. // this.$getKrpano().set(`hotspot[${data.name}].url`, data.img);
  603. },
  604. save() {
  605. this.$store.commit("SetHotspot", this.hotspot);
  606. this.$emit("close");
  607. this.$emit("save", this.hotspot);
  608. },
  609. },
  610. };
  611. </script>
  612. <style lang="less" scoped>
  613. .hots-panel {
  614. background: #252526;
  615. z-index: 10;
  616. display: flex;
  617. flex-direction: column;
  618. .header {
  619. padding: 20px;
  620. display: flex;
  621. font-size: 18px;
  622. color: #fff;
  623. flex: 0 0 auto;
  624. .icon_close {
  625. color: rgba(255, 255, 255, 0.6);
  626. cursor: pointer;
  627. }
  628. }
  629. .content {
  630. padding: 0 20px 14px 20px;
  631. flex: 1 0 1px;
  632. overflow: auto;
  633. .type-setting {
  634. .remark {
  635. font-size: 14px;
  636. color: #ababab;
  637. }
  638. .combox {
  639. margin-top: 16px;
  640. }
  641. }
  642. .icon-setting {
  643. .icon-setting-title {
  644. font-size: 18px;
  645. color: #ffffff;
  646. }
  647. .remark {
  648. margin-top: 16px;
  649. font-size: 14px;
  650. color: #ababab;
  651. }
  652. .combox {
  653. margin-top: 16px;
  654. }
  655. .icon-setting-component {
  656. margin-top: 16px;
  657. }
  658. .bars {
  659. margin-top: 16px;
  660. }
  661. }
  662. .title-setting {
  663. .remark-highlight {
  664. margin-top: 16px;
  665. font-size: 18px;
  666. color: #ffffff;
  667. }
  668. > .title-input-wrapper {
  669. position: relative;
  670. border: 1px solid rgba(151, 151, 151, 0.2);
  671. padding: 0 16px;
  672. background: #1a1b1d;
  673. border-radius: 2px;
  674. height: 36px;
  675. width: 100%;
  676. margin-top: 18px;
  677. &:focus-within {
  678. border-color: #0076f6;
  679. }
  680. > input {
  681. border: none;
  682. background: transparent;
  683. outline: none;
  684. height: 100%;
  685. width: calc(100% - 50px);
  686. padding: 0;
  687. color: #fff;
  688. letter-spacing: 1px;
  689. font-size: 14px;
  690. }
  691. > .count {
  692. position: absolute;
  693. top: 50%;
  694. transform: translateY(-50%);
  695. right: 16px;
  696. font-size: 14px;
  697. color: rgba(255, 255, 255, 0.2);
  698. }
  699. }
  700. .remark {
  701. margin-top: 18px;
  702. color: rgba(255, 255, 255, 0.6);
  703. font-size: 14px;
  704. }
  705. .display-mode-selector {
  706. margin-top: 18px;
  707. }
  708. }
  709. .effect-setting {
  710. margin-top: 16px;
  711. > .title-line {
  712. margin-top: 16px;
  713. display: flex;
  714. justify-content: space-between;
  715. align-items: center;
  716. > .remark-highlight {
  717. font-size: 18px;
  718. color: #ffffff;
  719. }
  720. > .tip {
  721. font-size: 14px;
  722. color: #ffffff;
  723. opacity: 0.6;
  724. }
  725. }
  726. .combox {
  727. margin-top: 16px;
  728. }
  729. .effect-setting-component {
  730. margin-top: 16px;
  731. }
  732. }
  733. }
  734. .footer {
  735. flex: 0 0 auto;
  736. padding: 15px;
  737. background: #252526;
  738. .deepcancel {
  739. margin-right: 10px;
  740. }
  741. .ui-button {
  742. width: 112px;
  743. }
  744. }
  745. }
  746. </style>