EditPanel.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <template>
  2. <transition appear name="custom-classes-transition" enter-active-class="animated slideInRight speed"
  3. leave-active-class="animated slideOutRight speed">
  4. <div class="hots-panel" v-show="show">
  5. <div class="ui-between header">
  6. <span>{{ editTitle }}{{ $i18n.t('hotspot.hotspot_name') }}</span>
  7. <i class="iconfont icon_close" @click="cancel"></i>
  8. </div>
  9. <div class="content" ref="content">
  10. <div class="icon-setting">
  11. <div class="icon-setting-title">{{ $i18n.t('hotspot.hotspot_icon') }}</div>
  12. <div class="remark">{{ $i18n.t('hotspot.select_icon') }}</div>
  13. <div class="icon-list">
  14. <div class="margin-handler-layer">
  15. <ul>
  16. <li :class="{ active: item.id == hotspot.icontype }" v-for="(item, i) in hotStyle"
  17. @click="addhotspot(item)" :key="i">
  18. <img :src="item.thumb" alt="">
  19. </li>
  20. </ul>
  21. </div>
  22. </div>
  23. <div class="bars">
  24. <RangeItem :value="rang" @input="onRangeChange" />
  25. </div>
  26. </div>
  27. <div class="title-setting">
  28. <div class="title-setting-title">{{ $i18n.t('hotspot.title_setting') }}</div>
  29. <div class="switch-wrapper">
  30. <span class="label">{{ $i18n.t('hotspot.isshow_title') }}</span>
  31. <Switcher :value="hotspot.visible" @change="hotspot.visible = !hotspot.visible"></Switcher>
  32. </div>
  33. <div class="title-input-wrapper">
  34. <input v-model.trim="hotspot.hotspotTitle" type="text" maxlength="50" :placeholder="$i18n.t('hotspot.title_placeholder')" />
  35. <span class="count">{{ hotspot.hotspotTitle.length }}/50</span>
  36. </div>
  37. </div>
  38. <div class="effect-setting">
  39. <div class="effect-setting-title">{{$i18n.t('hotspot.effect_settings')}}</div>
  40. <combox class="combox" :data="hotSpotTypeList" :selected-id="hotspot.hotspotType"
  41. :bottomSpace="comboxBottomSpace" @change="onhotSpotTypeChange"></combox>
  42. <component class="effect-setting-component" @sceneSelect="handleSceneSelect" :scene="hotspot.secne"
  43. @imageChange="data => { hotspot.image = data }" :image="hotspot.image"
  44. @linkChange="data => { hotspot.hyperlink = data }" :link="hotspot.hyperlink"
  45. @linkOpenType="data => { hotspot.linkOpenType = data }" :linkOpenType="hotspot.linkOpenType"
  46. @textChange="data => { hotspot.textarea = data }" :textarea="hotspot.textarea"
  47. @audioChange="data => { hotspot.audio = data }" :audio="hotspot.audio"
  48. @videoChange="data => { hotspot.video = data }" :video="hotspot.video" :is="effectSettingComponent" />
  49. </div>
  50. </div>
  51. <div class="ui-between footer" app-border dir-top>
  52. <button class="ui-button deepcancel" :class="{ disable: false }" @click="cancel">{{$i18n.t('hotspot.cancel')}}</button>
  53. <button class="ui-button submit" :class="{ disable: !canSubmit }" @click="save">{{$i18n.t('hotspot.finish')}}</button>
  54. </div>
  55. </div>
  56. </transition>
  57. </template>
  58. <script>
  59. import RangeItem from "@/components/rangeItem/index.vue";
  60. import Combox from "@/components/shared/Combox";
  61. import { mapGetters } from "vuex";
  62. import Switcher from "@/components/shared/Switcher.vue";
  63. let comparisonKey = [
  64. 'fontSize',
  65. 'hotspotTitle',
  66. 'hotspotType',
  67. 'hyperlink',
  68. 'icontype',
  69. 'image',
  70. 'img',
  71. 'link',
  72. 'secne',
  73. 'size',
  74. 'textarea',
  75. 'type',
  76. 'video'
  77. ]
  78. let HTMap = ''
  79. export default {
  80. props: ['show', 'data', 'editTitle'],
  81. components: {
  82. RangeItem,
  83. Combox,
  84. Switcher,
  85. },
  86. data() {
  87. let cdn = this.$config.getStaticResource('/panoassets/images/hotspot/icon/')
  88. let hotStyle = []
  89. for (let i = 0; i < 12; i++) {
  90. hotStyle[i] = {
  91. id: 'icon' + (i + 1),
  92. img: cdn + `img_doticon_${String(i + 1).padStart(2, '0')}.svg`,
  93. thumb: cdn + `img_doticon_${String(i + 1).padStart(2, '0')}.svg`
  94. }
  95. }
  96. HTMap = {
  97. scene: {
  98. key: 'secne',
  99. type: 'Object',
  100. errortxt: this.$i18n.t('hotspot.secne_errortxt')
  101. },
  102. audio: {
  103. key: 'audio',
  104. type: 'String',
  105. errortxt: this.$i18n.t('hotspot.audio_errortxt')
  106. },
  107. video: {
  108. key: 'video',
  109. type: 'String',
  110. errortxt: this.$i18n.t('hotspot.video_errortxt')
  111. },
  112. image: {
  113. key: 'image',
  114. type: 'Array',
  115. errortxt: this.$i18n.t('hotspot.image_errortxt')
  116. },
  117. link: {
  118. key: 'hyperlink',
  119. type: 'String',
  120. errortxt: this.$i18n.t('hotspot.link_errortxt')
  121. },
  122. textarea: {
  123. key: 'textarea',
  124. type: 'String',
  125. errortxt: this.$i18n.t('hotspot.textarea_errortxt')
  126. }
  127. }
  128. return {
  129. canSave: false,
  130. hotSpotTypeList: [
  131. {
  132. id: 'scene',
  133. name: this.$i18n.t('hotspot.secne')
  134. },
  135. {
  136. id: 'link',
  137. name: this.$i18n.t('hotspot.link')
  138. },
  139. {
  140. id: 'textarea',
  141. name: this.$i18n.t('hotspot.textarea')
  142. },
  143. {
  144. id: 'image',
  145. name: this.$i18n.t('hotspot.image')
  146. },
  147. {
  148. id: 'audio',
  149. name: this.$i18n.t('hotspot.audio')
  150. },
  151. {
  152. id: 'video',
  153. name: this.$i18n.t('hotspot.video')
  154. }
  155. ],
  156. hotStyle,
  157. rang: {
  158. label: this.$i18n.t('hotspot.icon_size'),
  159. unit: this.$i18n.t('hotspot.unit'),
  160. gradient: 0.5,
  161. value: 1,
  162. min: 0.5,
  163. max: 2,
  164. },
  165. selectItem: '',
  166. styIcon: '',
  167. linkicon: '',
  168. infoItem: '',
  169. isAdd: true,
  170. comboxBottomSpace: 0,
  171. }
  172. },
  173. watch: {
  174. 'hotspot.hotspotTitle': function () {
  175. this.$getKrpano().set('layer[tooltip_' + this.hotspot.name + '].html', this.hotspot.hotspotTitle)
  176. },
  177. 'hotspot.visible': function () {
  178. this.$getKrpano().set('layer[tooltip_' + this.hotspot.name + '].visible', this.hotspot.visible)
  179. },
  180. 'hotspot.size': {
  181. immediate: true,
  182. handler: function (newVal) {
  183. let h = 52
  184. let scaleH = h * newVal
  185. let offset = '-130%'
  186. this.rang = { ...this.rang, value: newVal }
  187. this.$getKrpano().set(`hotspot[${this.hotspot.name}].height`, scaleH)
  188. if (newVal < 1) {
  189. offset = '-200%'
  190. }
  191. if (newVal > 1) {
  192. offset = '-100%'
  193. }
  194. this.$getKrpano().set('layer[tooltip_' + this.hotspot.name + '].y', `${offset}`)
  195. }
  196. },
  197. 'hotspot.fontSize': {
  198. handler: function (newVal) {
  199. this.$getKrpano().set('layer[tooltip_' + this.hotspot.name + '].css', `text-align:center; color:#FFFFFF;
  200. font-family:STXihei;font-size:${newVal}px;`)
  201. }
  202. },
  203. show(newVal) {
  204. if (!newVal) {
  205. this.$bus.removeListener('selectUrl', this.listerFn)
  206. }
  207. }
  208. },
  209. beforeDestroy() {
  210. this.$bus.removeListener('selectUrl', this.listerFn)
  211. this.$bus.removeListener('resethotspotTitle', this.listerFnReset)
  212. },
  213. computed: {
  214. ...mapGetters({
  215. hotspot: 'hotspot',
  216. backupHotSpot: 'backupHotSpot',
  217. currentHPName: "tags/currentHPName"
  218. }),
  219. effectSettingComponent() {
  220. let tmp = this.hotspot.hotspotType
  221. return () => import(`./hotspotType/${tmp}.vue`);
  222. },
  223. canSubmit() {
  224. let { img, hotspotTitle, hotspotType } = this.hotspot
  225. let item = HTMap[hotspotType]
  226. if (!img) {
  227. // return this.$alert({
  228. // content: this.$i18n.t('hotspot.select_hotspot_icon'),
  229. // });
  230. return false
  231. }
  232. if (!(hotspotTitle.trim()/* && (hotspotTitle.trim() != this.$i18n.t('hotspot.click_to_comfirm'))*/)) {
  233. // return this.$alert({
  234. // content: this.$i18n.t('hotspot.input_hotspot_title'),
  235. // });
  236. return false
  237. }
  238. if (!this.hotspot[item.key] || (item.type == 'Array' && this.hotspot[item.key].length <= 0)) {
  239. // return this.$alert({
  240. // content: `${item.errortxt}`,
  241. // });
  242. return false
  243. }
  244. return true
  245. }
  246. },
  247. mounted() {
  248. this.selectItem = {
  249. sceneCode: this.infoItem.link
  250. }
  251. this.$bus.on('selectUrl', this.listerFn)
  252. this.$bus.on('resethotspotTitle', this.listerFnReset)
  253. this.$bus.on('delhotspot', () => {
  254. this.cancel()
  255. })
  256. this.$nextTick(() => {
  257. if (this.editTitle != '编辑'&&this.editTitle != this.$i18n.t('hotspot.edit')) {
  258. this.addhotspot(this.hotStyle[0])
  259. this.rang.value = window.g_hotspotCurrentScale
  260. this.onRangeChange({ value: window.g_hotspotCurrentScale })
  261. }
  262. this.comboxBottomSpace = this.$refs.content.getBoundingClientRect().bottom
  263. })
  264. },
  265. methods: {
  266. handleSceneSelect(data) {
  267. this.hotspot.secne = {
  268. ...data,
  269. someData: {}
  270. }
  271. },
  272. onhotSpotTypeChange(data) {
  273. this.hotspot.hotspotType = data.id
  274. },
  275. onRangeChange(data) {
  276. console.log(data);
  277. this.rang = { ...this.rang, value: data.value }
  278. this.hotspot.size = data.value
  279. switch (data.value) {
  280. case 0.5:
  281. this.hotspot.fontSize = 12
  282. break;
  283. case 1:
  284. this.hotspot.fontSize = 14
  285. break;
  286. case 1.5:
  287. this.hotspot.fontSize = 17
  288. break;
  289. case 2:
  290. this.hotspot.fontSize = 20
  291. break;
  292. default:
  293. console.error('unexpected range value: ', data.value);
  294. break;
  295. }
  296. },
  297. listerFnReset() {
  298. if (this.hotspot.hotspotTitle == '单击确定热点位置'||this.hotspot.hotspotTitle == this.$i18n.t('hotspot.click_to_comfirm')) {
  299. this.hotspot.hotspotTitle = ''
  300. }
  301. },
  302. listerFn(data) {
  303. this.selectItem = {
  304. sceneCode: data.sceneCode
  305. }
  306. this.infoItem.link = data.sceneCode
  307. this.infoItem.thumb = data.icon
  308. },
  309. isDiffHotSpot() {
  310. let flag = false
  311. comparisonKey.forEach(item => {
  312. if (JSON.stringify(this.hotspot[item]) != JSON.stringify(this.backupHotSpot[item])) {
  313. flag = true
  314. }
  315. })
  316. return flag
  317. },
  318. isAddChange() {
  319. let flag = false
  320. let { hotspotTitle, hotspotType } = this.hotspot
  321. let item = HTMap[hotspotType]
  322. if (
  323. (hotspotTitle.trim() && (hotspotTitle.trim() != '单击确定热点位置'&&hotspotTitle.trim() != this.$i18n.t('hotspot.click_to_comfirm')))
  324. || this.hotspot[item.key]
  325. || (item.type == 'Array' && this.hotspot[item.key].length > 0)
  326. ) {
  327. flag = true
  328. }
  329. return flag
  330. },
  331. cancel() {
  332. this.$store.commit("SetHotspot", this.backupHotSpot);
  333. this.$emit("close", {
  334. type: this.editTitle == this.$i18n.t('hotspot.edit') ? 'edit' : 'add',
  335. data: this.backupHotSpot
  336. });
  337. },
  338. reset(data) {
  339. this.$bus.emit('edithotspotTitle', data)
  340. this.$bus.emit('edithotspotTitleisShow', data)
  341. this.$getKrpano().set(`hotspot[${data.name}].url`, data.img)
  342. },
  343. save() {
  344. this.$store.commit("SetHotspot", this.hotspot);
  345. this.$emit("close");
  346. this.$emit("save", this.hotspot);
  347. },
  348. addhotspot(data) {
  349. console.log(this.isAdd, 'this.isAdd');
  350. if (this.isAdd && (this.editTitle != '编辑'&&this.editTitle != this.$i18n.t('hotspot.edit'))) {
  351. this.isAdd = false
  352. this.hotspot.img = data.img
  353. this.hotspot.icontype = data.id
  354. this.styIcon = data.id
  355. this.$bus.emit('addhotspot', this.hotspot)
  356. this.$getKrpano().set('layer[tooltip_' + this.hotspot.name + '].css', `text-align:center; color:#FFFFFF;
  357. font-family:STXihei;font-size:${this.hotspot.fontSize}px;`)
  358. }
  359. else {
  360. this.hotspot.img = data.img
  361. this.hotspot.icontype = data.id
  362. this.styIcon = data.id
  363. this.$getKrpano().set(`hotspot[${this.hotspot.name}].url`, data.img)
  364. this.$getKrpano().set(`hotspot[${this.hotspot.name}].hotspottitle`, this.hotspot.hotspotTitle)
  365. }
  366. }
  367. }
  368. };
  369. </script>
  370. <style lang="less" scoped>
  371. .hots-panel {
  372. background: #1A1B1D;
  373. z-index: 10;
  374. display: flex;
  375. flex-direction: column;
  376. .header {
  377. padding: 20px;
  378. display: flex;
  379. font-size: 18px;
  380. color: #fff;
  381. flex: 0 0 auto;
  382. .icon_close {
  383. color: rgba(255, 255, 255, 0.6);
  384. cursor: pointer;
  385. }
  386. }
  387. .content {
  388. padding: 20px 20px 14px 20px;
  389. background: #252526;
  390. flex: 1 0 1px;
  391. overflow: auto;
  392. .icon-setting {
  393. .icon-setting-title {
  394. font-size: 18px;
  395. color: #FFFFFF;
  396. }
  397. .remark {
  398. margin-top: 16px;
  399. font-size: 14px;
  400. color: #ababab;
  401. }
  402. .icon-list {
  403. margin-top: 16px;
  404. height: 158px;
  405. background: #1A1B1D;
  406. border-radius: 2px;
  407. border: 1px solid #404040;
  408. overflow: auto;
  409. padding: 4px;
  410. >.margin-handler-layer {
  411. overflow: hidden;
  412. ul {
  413. display: flex;
  414. align-items: center;
  415. flex-wrap: wrap;
  416. margin-right: -17px;
  417. margin-bottom: -17px;
  418. li {
  419. cursor: pointer;
  420. margin-right: 17px;
  421. margin-bottom: 17px;
  422. width: 38px;
  423. height: 38px;
  424. border: solid 2px transparent;
  425. border-radius: 4px;
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. position: relative;
  430. &::after {
  431. position: absolute;
  432. content: '';
  433. height: 100%;
  434. width: 100%;
  435. left: 0;
  436. right: 0;
  437. top: 0;
  438. bottom: 0;
  439. background-image: url(~@/assets/images/icons/gif@2x.png);
  440. background-size: 100% auto;
  441. z-index: 999;
  442. pointer-events: none;
  443. }
  444. &.active {
  445. border-color: #0076f6;
  446. }
  447. }
  448. }
  449. }
  450. }
  451. .bars {
  452. margin-top: 16px;
  453. }
  454. }
  455. .title-setting {
  456. margin-top: 24px;
  457. .title-setting-title {
  458. font-size: 18px;
  459. color: #FFFFFF;
  460. }
  461. .switch-wrapper {
  462. display: flex;
  463. align-items: center;
  464. justify-content: space-between;
  465. margin-top: 18px;
  466. .label {
  467. color: rgba(255, 255, 255, 0.6);
  468. font-size: 14px;
  469. }
  470. }
  471. >.title-input-wrapper {
  472. position: relative;
  473. border: 1px solid rgba(151, 151, 151, 0.2);
  474. padding: 0 16px;
  475. background: #1A1B1D;
  476. border-radius: 2px;
  477. height: 36px;
  478. width: 100%;
  479. margin-top: 18px;
  480. &:focus-within {
  481. border-color: #0076F6;
  482. }
  483. >input {
  484. border: none;
  485. background: transparent;
  486. outline: none;
  487. height: 100%;
  488. width: calc(100% - 50px);
  489. padding: 0;
  490. color: #fff;
  491. letter-spacing: 1px;
  492. font-size: 14px;
  493. }
  494. >.count {
  495. position: absolute;
  496. top: 50%;
  497. transform: translateY(-50%);
  498. right: 16px;
  499. font-size: 14px;
  500. color: rgba(255, 255, 255, 0.2);
  501. }
  502. }
  503. }
  504. .effect-setting {
  505. margin-top: 16px;
  506. .effect-setting-title {
  507. font-size: 18px;
  508. color: #FFFFFF;
  509. }
  510. .combox {
  511. margin-top: 16px;
  512. }
  513. .effect-setting-component {
  514. margin-top: 16px;
  515. }
  516. }
  517. }
  518. .footer {
  519. flex: 0 0 auto;
  520. padding: 15px;
  521. background: #252526;
  522. .deepcancel {
  523. margin-right: 10px;
  524. }
  525. .ui-button {
  526. width: 112px;
  527. }
  528. }
  529. }
  530. </style>