customButtonSettings.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <div class="custom-button-settings">
  3. <span class="title">自定义按钮</span>
  4. <i class="iconfont icon-material_prompt tool-tip-for-editor" v-tooltip="'自定义按钮可为作品添加联系方式或网站链接等,设置可见后即可在作品显示。'">
  5. </i>
  6. <br/>
  7. <div v-for="(item, index) of info.customButton" :key="index" class="button-setting-item" :class="{expand: expandStatus[index]}">
  8. <div
  9. class="title-bar"
  10. :class="info.customButton[index].isShow ? 'bright' : 'dark'"
  11. @click="onRequestForChangeExpandStatus(index)"
  12. >
  13. <div class="left">
  14. <i
  15. class="iconfont icon-edit_input_arrow icon-expand"
  16. ></i>
  17. <img v-if="info.customButton[index].type === '电话' && info.customButton[index].isShow" :src="require('@/assets/images/icons/phone.svg')" class="button-icon" alt="">
  18. <img v-if="info.customButton[index].type === '电话' && !info.customButton[index].isShow" :src="require('@/assets/images/icons/phone-dark.svg')" class="button-icon" alt="">
  19. <img v-if="info.customButton[index].type === '链接' && info.customButton[index].isShow" :src="require('@/assets/images/icons/link.svg')" class="button-icon" alt="">
  20. <img v-if="info.customButton[index].type === '链接' && !info.customButton[index].isShow" :src="require('@/assets/images/icons/link-dark.svg')" class="button-icon" alt="">
  21. <span class="button-name">
  22. {{info.customButton[index].name}}
  23. </span>
  24. </div>
  25. <div class="right">
  26. <i
  27. class="iconfont icon-editor_list_edit btn-edit"
  28. @click.stop="onRequestForEdit(index)"
  29. v-tooltip="'编辑'"
  30. >
  31. </i>
  32. <i
  33. v-show="info.customButton[index].isShow"
  34. class="iconfont icon-editor_on btn-show"
  35. v-tooltip="'隐藏'"
  36. @click.stop="info.customButton[index].isShow = false"
  37. ></i>
  38. <i
  39. v-show="!info.customButton[index].isShow"
  40. class="iconfont icon-editor_off btn-hide"
  41. v-tooltip="'显示'"
  42. @click.stop="onRequestForShow(index)"
  43. ></i>
  44. </div>
  45. </div>
  46. <div class="edit-content">
  47. <div class="edit-content-item">
  48. <span class="item-name">按钮名称</span>
  49. <PulldownMenuInEditor
  50. class="selector"
  51. :valueList="buttonTypeList"
  52. v-model="info.customButton[index].type"
  53. ></PulldownMenuInEditor>
  54. <input
  55. class="name-input"
  56. placeholder="请输入按钮名称"
  57. v-model="info.customButton[index].name"
  58. maxlength="15"
  59. >
  60. </div>
  61. <div class="edit-content-item">
  62. <span class="item-name">{{buttonValueTips[index]}}</span>
  63. <input
  64. class="value-input"
  65. v-model="info.customButton[index].value"
  66. >
  67. </div>
  68. </div>
  69. </div>
  70. <popup v-if="isEditing" :canClose="false">
  71. <div class="ui-message ui-message-confirm dark edit-window">
  72. <div class="ui-message-header">
  73. <span>自定义按钮</span>
  74. <span @click="isEditing = false">
  75. <i class="iconfont icon_close"></i>
  76. </span>
  77. </div>
  78. <div class="ui-message-main">
  79. <div class="edit-content-item">
  80. <span class="item-name">按钮名称</span>
  81. <PulldownMenuInEditor
  82. class="selector"
  83. :valueList="buttonTypeList"
  84. v-model="editingInfo.type"
  85. ></PulldownMenuInEditor>
  86. <input
  87. class="name-input"
  88. placeholder="请输入按钮名称"
  89. v-model="editingInfo.name"
  90. maxlength="15"
  91. >
  92. </div>
  93. <div class="edit-content-item">
  94. <span class="item-name">{{editingButtonValueTip}}</span>
  95. <input
  96. class="value-input"
  97. :placeholder="`请输入${editingButtonValueTip}`"
  98. v-model="editingInfo.value"
  99. >
  100. </div>
  101. </div>
  102. <div class="ui-message-footer">
  103. <button class="ui-button deepcancel" @click="isEditing = false">
  104. 取消
  105. </button>
  106. <button
  107. class="ui-button submit"
  108. @click="onConfirmEditing"
  109. >
  110. 确定
  111. </button>
  112. </div>
  113. </div>
  114. </popup>
  115. </div>
  116. </template>
  117. <script>
  118. import { mapGetters } from "vuex";
  119. import PulldownMenuInEditor from "@/components/pulldownMenuInEditor.vue";
  120. import { isValidPhoneNumber } from "@/utils/other.js";
  121. import Popup from "@/components/shared/popup/index.vue";
  122. export default {
  123. components: {
  124. PulldownMenuInEditor,
  125. Popup,
  126. },
  127. data() {
  128. return {
  129. expandStatus: [],
  130. buttonTypeList: [
  131. '电话',
  132. '链接',
  133. ],
  134. isEditing: false,
  135. editingButtonIdx: -1,
  136. isIgnoreTypeChangeWhenEditing: false,
  137. editingInfo: {
  138. type: '',
  139. name: '',
  140. value: '',
  141. }
  142. }
  143. },
  144. computed: {
  145. ...mapGetters({
  146. info:'info'
  147. }),
  148. buttonValueTips() {
  149. if (this?.info?.customButton) {
  150. return this.info.customButton.map((item) => {
  151. if (item.type === '电话') {
  152. return '电话号码'
  153. } else if (item.type === '链接') {
  154. return '链接地址'
  155. } else {
  156. return ''
  157. }
  158. })
  159. } else {
  160. return null
  161. }
  162. },
  163. editingButtonValueTip() {
  164. if (this.editingInfo.type === '电话') {
  165. return '电话号码'
  166. } else if (this.editingInfo.type === '链接') {
  167. return '链接地址'
  168. } else {
  169. return ''
  170. }
  171. },
  172. },
  173. watch: {
  174. 'editingInfo.type': {
  175. handler(vNew) {
  176. if (!this.isIgnoreTypeChangeWhenEditing) {
  177. this.editingInfo.name = vNew
  178. this.editingInfo.value = ''
  179. }
  180. this.isIgnoreTypeChangeWhenEditing = false
  181. }
  182. },
  183. },
  184. beforeMount() {
  185. if (!this.info.customButton) {
  186. // 这是在v1.2版之前创建的作品,还没设置过自定义按钮,所以还没有customButton字段
  187. this.info.customButton = [
  188. {
  189. "type": "电话",
  190. "name": "电话",
  191. "value": "",
  192. "isShow": false
  193. },
  194. {
  195. "type": "链接",
  196. "name": "链接",
  197. "value": "",
  198. "isShow": false
  199. }
  200. ]
  201. }
  202. },
  203. methods: {
  204. onRequestForChangeExpandStatus(index) {
  205. this.$set(this.expandStatus, index, !this.expandStatus[index])
  206. },
  207. onRequestForEdit(index) {
  208. this.editingButtonIdx = index
  209. this.isIgnoreTypeChangeWhenEditing = true,
  210. this.editingInfo.type = this.info.customButton[index].type
  211. this.editingInfo.name = this.info.customButton[index].name
  212. this.editingInfo.value = this.info.customButton[index].value
  213. this.isEditing = true
  214. },
  215. checkButtonName(name) {
  216. if (!name) {
  217. this.$msg.warning('请填写完整信息')
  218. return false
  219. }
  220. return true
  221. },
  222. checkButtonValue(value, type) {
  223. if (type === '电话') {
  224. if (!isValidPhoneNumber(value)) {
  225. this.$msg.warning('请正确填写电话号码')
  226. return false
  227. }
  228. } else if (type === '链接') {
  229. if (!value) {
  230. this.$msg.warning('请填写完整信息')
  231. return false
  232. }
  233. }
  234. return true
  235. },
  236. onConfirmEditing() {
  237. if (!this.checkButtonName(this.editingInfo.name)) {
  238. return
  239. }
  240. if (!this.checkButtonValue(this.editingInfo.value, this.editingInfo.type)) {
  241. return
  242. }
  243. this.info.customButton[this.editingButtonIdx].type = this.editingInfo.type
  244. this.info.customButton[this.editingButtonIdx].name = this.editingInfo.name
  245. this.info.customButton[this.editingButtonIdx].value = this.editingInfo.value
  246. this.$msg.success('操作成功')
  247. this.isEditing = false
  248. },
  249. onRequestForShow(index) {
  250. if (!this.checkButtonName(this.info.customButton[index].name)) {
  251. return
  252. }
  253. if (!this.checkButtonValue(this.info.customButton[index].value, this.info.customButton[index].type)) {
  254. return
  255. }
  256. this.info.customButton[index].isShow = true
  257. }
  258. }
  259. }
  260. </script>
  261. <style lang="less" scoped>
  262. .custom-button-settings {
  263. padding: 24px 30px;
  264. background: #252526;
  265. height: 546px;
  266. .title {
  267. font-size: 18px;
  268. color: #FFFFFF;
  269. }
  270. .tool-tip-for-editor {
  271. margin-left: 4px;
  272. font-size: 12px;
  273. cursor: default;
  274. position: relative;
  275. top: -2px;
  276. }
  277. > .button-setting-item {
  278. margin-top: 16px;
  279. position: relative;
  280. min-height: 50px;
  281. > .title-bar {
  282. position: absolute;
  283. width: 100%;
  284. height: 50px;
  285. background: #1A1B1D;
  286. border-radius: 2px;
  287. border: 1px solid #404040;
  288. display: flex;
  289. justify-content: space-between;
  290. align-items: center;
  291. padding: 0 16px;
  292. cursor: pointer;
  293. &.bright {
  294. color: #fff;
  295. }
  296. &.dark {
  297. color: #808080;
  298. }
  299. > .left {
  300. display: flex;
  301. align-items: center;
  302. > .icon-expand {
  303. font-size: 10px;
  304. color: rgba(255, 255, 255, 0.6);
  305. transform: rotate(-90deg);
  306. cursor: pointer;
  307. }
  308. > .button-icon {
  309. width: 18px;
  310. height: 18px;
  311. margin-left: 6px;
  312. }
  313. > .button-name {
  314. font-size: 16px;
  315. margin-left: 6px;
  316. }
  317. }
  318. > .right {
  319. display: flex;
  320. align-items: center;
  321. i.btn-edit {
  322. margin-left: 16px;
  323. cursor: pointer;
  324. &:hover {
  325. color: #0076F6;
  326. }
  327. }
  328. > .btn-show {
  329. margin-left: 16px;
  330. cursor: pointer;
  331. &:hover {
  332. color: #0076F6;
  333. }
  334. }
  335. > .btn-hide {
  336. margin-left: 16px;
  337. cursor: pointer;
  338. &:hover {
  339. color: #0076F6;
  340. }
  341. }
  342. }
  343. }
  344. > .edit-content {
  345. border-radius: 2px;
  346. border: 1px solid #404040;
  347. padding-top: 58px;
  348. padding-bottom: 26px;
  349. display: none;
  350. pointer-events: none;
  351. > .edit-content-item {
  352. margin-top: 16px;
  353. display: flex;
  354. align-items: center;
  355. > .item-name {
  356. margin-left: 16px;
  357. font-size: 14px;
  358. color: rgba(255, 255, 255, 0.5)
  359. }
  360. > .selector {
  361. margin-left: 16px;
  362. }
  363. > .name-input {
  364. height: 36px;
  365. background: transparent;
  366. border-radius: 2px;
  367. border: 1px solid #404040;
  368. color: #fff;
  369. font-size: 14px;
  370. padding: 0 16px;
  371. letter-spacing: 1px;
  372. width: 470px;
  373. &:focus {
  374. border-color: #0076F6;
  375. }
  376. }
  377. > .value-input {
  378. margin-left: 16px;
  379. height: 36px;
  380. background: transparent;
  381. border-radius: 2px;
  382. border: 1px solid #404040;
  383. color: #fff;
  384. font-size: 14px;
  385. padding: 0 16px;
  386. letter-spacing: 1px;
  387. width: 610px;
  388. &:focus {
  389. border-color: #0076F6;
  390. }
  391. }
  392. }
  393. }
  394. }
  395. > .button-setting-item.expand {
  396. > .title-bar {
  397. > .left {
  398. > .icon-expand {
  399. transform: rotate(0deg);
  400. }
  401. }
  402. }
  403. > .edit-content {
  404. display: block;
  405. }
  406. }
  407. .edit-window {
  408. width: 574px;
  409. > .ui-message-main {
  410. margin-bottom: 40px;
  411. > .edit-content-item {
  412. margin-top: 16px;
  413. display: flex;
  414. align-items: center;
  415. > .item-name {
  416. flex: 0 0 auto;
  417. font-size: 14px;
  418. color: rgba(255, 255, 255, 0.5)
  419. }
  420. > .selector {
  421. margin-left: 16px;
  422. }
  423. > .name-input {
  424. height: 36px;
  425. background: #252526;
  426. border-radius: 2px;
  427. border: 1px solid #404040;
  428. color: #fff;
  429. font-size: 14px;
  430. padding: 0 16px;
  431. letter-spacing: 1px;
  432. width: 470px;
  433. &:focus {
  434. border-color: #0076F6;
  435. }
  436. }
  437. > .value-input {
  438. margin-left: 16px;
  439. height: 36px;
  440. background: #252526;
  441. border-radius: 2px;
  442. border: 1px solid #404040;
  443. color: #fff;
  444. font-size: 14px;
  445. padding: 0 16px;
  446. letter-spacing: 1px;
  447. width: 610px;
  448. &:focus {
  449. border-color: #0076F6;
  450. }
  451. }
  452. }
  453. }
  454. }
  455. }
  456. </style>