123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- <template>
- <div class="custom-button-settings">
- <span class="title">自定义按钮</span>
- <i class="iconfont icon-material_prompt tool-tip-for-editor" v-tooltip="'自定义按钮可为作品添加联系方式或网站链接等,设置可见后即可在作品显示。'">
- </i>
- <br/>
-
- <div v-for="(item, index) of info.customButton" :key="index" class="button-setting-item" :class="{expand: expandStatus[index]}">
- <div
- class="title-bar"
- :class="info.customButton[index].isShow ? 'bright' : 'dark'"
- @click="onRequestForChangeExpandStatus(index)"
- >
- <div class="left">
- <i
- class="iconfont icon-edit_input_arrow icon-expand"
- ></i>
- <img v-if="info.customButton[index].type === '电话' && info.customButton[index].isShow" :src="require('@/assets/images/icons/phone.svg')" class="button-icon" alt="">
- <img v-if="info.customButton[index].type === '电话' && !info.customButton[index].isShow" :src="require('@/assets/images/icons/phone-dark.svg')" class="button-icon" alt="">
- <img v-if="info.customButton[index].type === '链接' && info.customButton[index].isShow" :src="require('@/assets/images/icons/link.svg')" class="button-icon" alt="">
- <img v-if="info.customButton[index].type === '链接' && !info.customButton[index].isShow" :src="require('@/assets/images/icons/link-dark.svg')" class="button-icon" alt="">
- <span class="button-name">
- {{info.customButton[index].name}}
- </span>
- </div>
- <div class="right">
- <i
- class="iconfont icon-editor_list_edit btn-edit"
- @click.stop="onRequestForEdit(index)"
- v-tooltip="'编辑'"
- >
- </i>
- <i
- v-show="info.customButton[index].isShow"
- class="iconfont icon-editor_on btn-show"
- v-tooltip="'隐藏'"
- @click.stop="info.customButton[index].isShow = false"
- ></i>
- <i
- v-show="!info.customButton[index].isShow"
- class="iconfont icon-editor_off btn-hide"
- v-tooltip="'显示'"
- @click.stop="onRequestForShow(index)"
- ></i>
- </div>
- </div>
- <div class="edit-content">
- <div class="edit-content-item">
- <span class="item-name">按钮名称</span>
- <PulldownMenuInEditor
- class="selector"
- :valueList="buttonTypeList"
- v-model="info.customButton[index].type"
- ></PulldownMenuInEditor>
- <input
- class="name-input"
- placeholder="请输入按钮名称"
- v-model="info.customButton[index].name"
- maxlength="15"
- >
- </div>
- <div class="edit-content-item">
- <span class="item-name">{{buttonValueTips[index]}}</span>
- <input
- class="value-input"
- v-model="info.customButton[index].value"
- >
- </div>
- </div>
- </div>
- <popup v-if="isEditing" :canClose="false">
- <div class="ui-message ui-message-confirm dark edit-window">
- <div class="ui-message-header">
- <span>自定义按钮</span>
- <span @click="isEditing = false">
- <i class="iconfont icon_close"></i>
- </span>
- </div>
- <div class="ui-message-main">
- <div class="edit-content-item">
- <span class="item-name">按钮名称</span>
- <PulldownMenuInEditor
- class="selector"
- :valueList="buttonTypeList"
- v-model="editingInfo.type"
- ></PulldownMenuInEditor>
- <input
- class="name-input"
- placeholder="请输入按钮名称"
- v-model="editingInfo.name"
- maxlength="15"
- >
- </div>
- <div class="edit-content-item">
- <span class="item-name">{{editingButtonValueTip}}</span>
- <input
- class="value-input"
- :placeholder="`请输入${editingButtonValueTip}`"
- v-model="editingInfo.value"
- >
- </div>
- </div>
- <div class="ui-message-footer">
- <button class="ui-button deepcancel" @click="isEditing = false">
- 取消
- </button>
- <button
- class="ui-button submit"
- @click="onConfirmEditing"
- >
- 确定
- </button>
- </div>
- </div>
- </popup>
- </div>
- </template>
- <script>
- import { mapGetters } from "vuex";
- import PulldownMenuInEditor from "@/components/pulldownMenuInEditor.vue";
- import { isValidPhoneNumber } from "@/utils/other.js";
- import Popup from "@/components/shared/popup/index.vue";
- export default {
- components: {
- PulldownMenuInEditor,
- Popup,
- },
- data() {
- return {
- expandStatus: [],
- buttonTypeList: [
- '电话',
- '链接',
- ],
- isEditing: false,
- editingButtonIdx: -1,
- isIgnoreTypeChangeWhenEditing: false,
- editingInfo: {
- type: '',
- name: '',
- value: '',
- }
- }
- },
- computed: {
- ...mapGetters({
- info:'info'
- }),
- buttonValueTips() {
- if (this?.info?.customButton) {
- return this.info.customButton.map((item) => {
- if (item.type === '电话') {
- return '电话号码'
- } else if (item.type === '链接') {
- return '链接地址'
- } else {
- return ''
- }
- })
- } else {
- return null
- }
- },
- editingButtonValueTip() {
- if (this.editingInfo.type === '电话') {
- return '电话号码'
- } else if (this.editingInfo.type === '链接') {
- return '链接地址'
- } else {
- return ''
- }
- },
- },
- watch: {
- 'editingInfo.type': {
- handler(vNew) {
- if (!this.isIgnoreTypeChangeWhenEditing) {
- this.editingInfo.name = vNew
- this.editingInfo.value = ''
- }
- this.isIgnoreTypeChangeWhenEditing = false
- }
- },
- },
- beforeMount() {
- if (!this.info.customButton) {
- // 这是在v1.2版之前创建的作品,还没设置过自定义按钮,所以还没有customButton字段
- this.info.customButton = [
- {
- "type": "电话",
- "name": "电话",
- "value": "",
- "isShow": false
- },
- {
- "type": "链接",
- "name": "链接",
- "value": "",
- "isShow": false
- }
- ]
- }
- },
- methods: {
- onRequestForChangeExpandStatus(index) {
- this.$set(this.expandStatus, index, !this.expandStatus[index])
- },
- onRequestForEdit(index) {
- this.editingButtonIdx = index
- this.isIgnoreTypeChangeWhenEditing = true,
- this.editingInfo.type = this.info.customButton[index].type
- this.editingInfo.name = this.info.customButton[index].name
- this.editingInfo.value = this.info.customButton[index].value
- this.isEditing = true
- },
- checkButtonName(name) {
- if (!name) {
- this.$msg.warning('请填写完整信息')
- return false
- }
- return true
- },
- checkButtonValue(value, type) {
- if (type === '电话') {
- if (!isValidPhoneNumber(value)) {
- this.$msg.warning('请正确填写电话号码')
- return false
- }
- } else if (type === '链接') {
- if (!value) {
- this.$msg.warning('请填写完整信息')
- return false
- }
- }
- return true
- },
- onConfirmEditing() {
- if (!this.checkButtonName(this.editingInfo.name)) {
- return
- }
- if (!this.checkButtonValue(this.editingInfo.value, this.editingInfo.type)) {
- return
- }
- this.info.customButton[this.editingButtonIdx].type = this.editingInfo.type
- this.info.customButton[this.editingButtonIdx].name = this.editingInfo.name
- this.info.customButton[this.editingButtonIdx].value = this.editingInfo.value
- this.$msg.success('操作成功')
- this.isEditing = false
- },
- onRequestForShow(index) {
- if (!this.checkButtonName(this.info.customButton[index].name)) {
- return
- }
- if (!this.checkButtonValue(this.info.customButton[index].value, this.info.customButton[index].type)) {
- return
- }
- this.info.customButton[index].isShow = true
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .custom-button-settings {
- padding: 24px 30px;
- background: #252526;
- height: 546px;
- .title {
- font-size: 18px;
- color: #FFFFFF;
- }
- .tool-tip-for-editor {
- margin-left: 4px;
- font-size: 12px;
- cursor: default;
- position: relative;
- top: -2px;
- }
- > .button-setting-item {
- margin-top: 16px;
- position: relative;
- min-height: 50px;
- > .title-bar {
- position: absolute;
- width: 100%;
- height: 50px;
- background: #1A1B1D;
- border-radius: 2px;
- border: 1px solid #404040;
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 0 16px;
- cursor: pointer;
- &.bright {
- color: #fff;
- }
- &.dark {
- color: #808080;
- }
- > .left {
- display: flex;
- align-items: center;
- > .icon-expand {
- font-size: 10px;
- color: rgba(255, 255, 255, 0.6);
- transform: rotate(-90deg);
- cursor: pointer;
- }
- > .button-icon {
- width: 18px;
- height: 18px;
- margin-left: 6px;
- }
- > .button-name {
- font-size: 16px;
- margin-left: 6px;
- }
- }
- > .right {
- display: flex;
- align-items: center;
- i.btn-edit {
- margin-left: 16px;
- cursor: pointer;
- &:hover {
- color: #0076F6;
- }
- }
- > .btn-show {
- margin-left: 16px;
- cursor: pointer;
- &:hover {
- color: #0076F6;
- }
- }
- > .btn-hide {
- margin-left: 16px;
- cursor: pointer;
- &:hover {
- color: #0076F6;
- }
- }
- }
- }
- > .edit-content {
- border-radius: 2px;
- border: 1px solid #404040;
- padding-top: 58px;
- padding-bottom: 26px;
- display: none;
- pointer-events: none;
- > .edit-content-item {
- margin-top: 16px;
- display: flex;
- align-items: center;
- > .item-name {
- margin-left: 16px;
- font-size: 14px;
- color: rgba(255, 255, 255, 0.5)
- }
- > .selector {
- margin-left: 16px;
- }
- > .name-input {
- height: 36px;
- background: transparent;
- border-radius: 2px;
- border: 1px solid #404040;
- color: #fff;
- font-size: 14px;
- padding: 0 16px;
- letter-spacing: 1px;
- width: 470px;
- &:focus {
- border-color: #0076F6;
- }
- }
- > .value-input {
- margin-left: 16px;
- height: 36px;
- background: transparent;
- border-radius: 2px;
- border: 1px solid #404040;
- color: #fff;
- font-size: 14px;
- padding: 0 16px;
- letter-spacing: 1px;
- width: 610px;
- &:focus {
- border-color: #0076F6;
- }
- }
- }
- }
- }
- > .button-setting-item.expand {
- > .title-bar {
- > .left {
- > .icon-expand {
- transform: rotate(0deg);
- }
- }
- }
- > .edit-content {
- display: block;
- }
- }
- .edit-window {
- width: 574px;
- > .ui-message-main {
- margin-bottom: 40px;
- > .edit-content-item {
- margin-top: 16px;
- display: flex;
- align-items: center;
- > .item-name {
- flex: 0 0 auto;
- font-size: 14px;
- color: rgba(255, 255, 255, 0.5)
- }
- > .selector {
- margin-left: 16px;
- }
- > .name-input {
- height: 36px;
- background: #252526;
- border-radius: 2px;
- border: 1px solid #404040;
- color: #fff;
- font-size: 14px;
- padding: 0 16px;
- letter-spacing: 1px;
- width: 470px;
- &:focus {
- border-color: #0076F6;
- }
- }
- > .value-input {
- margin-left: 16px;
- height: 36px;
- background: #252526;
- border-radius: 2px;
- border: 1px solid #404040;
- color: #fff;
- font-size: 14px;
- padding: 0 16px;
- letter-spacing: 1px;
- width: 610px;
- &:focus {
- border-color: #0076F6;
- }
- }
- }
- }
- }
- }
- </style>
|