123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- <style lang="scss">
- .theme-card-item {
- user-select: none;
- border-radius: 4px;
- overflow: hidden;
- background: #fff;
- height: 90%;
- margin: 25px 0;
- box-shadow: 0 0 1px 0 #666;
- &.is-hidden {
- opacity: 0;
- height: 0;
- }
- .upload {
- cursor: pointer;
- background: #f5f7fa;
- height: 100%;
- width: 100%;
- display: flex;
- justify-content: center;
- align-items:center;
- .upload-action {
- width: 40%;
- margin: 0 auto;
- text-align: center;
- color: #606266;
- img {
- display: block;
- margin: 0 auto;
- }
- span {
- display: block;
- font-size: 14px;
- margin-top: 8px;
- }
- }
- }
- .preview {
- position: relative;
- height: 70%;
- width: 100%;
- .line {
- height: 50%;
- }
- .line-2 {
- width: 50%;
- height: 100%;
- display: inline-block;
- }
- .line-4 {
- width: 25%;
- height: 100%;
- display: inline-block;
- }
- .action {
- transition: all .3s;
- position: absolute;
- opacity: 0;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .action-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: #000;
- opacity: 0.4;
- }
- .action-block {
- position: absolute;
- width: 50%;
- height: 50%;
- left: 25%;
- top: 25%;
- }
- .action-item {
- cursor: pointer;
- display: inline-block;
- height: 100%;
- width: 30%;
- color: #eee;
- &:hover {
- color: #fff;
- .circle {
- border-color: #fff;
- }
- }
- .icon {
- height: 50%;
- font-size: 22px;
- text-align: center;
- display: flex;
- justify-content:center;
- align-items:center;
- img {
- width: 130%;
- }
- }
- .name {
- font-size: 12px;
- height: 50%;
- text-align: center;
- display: flex;
- justify-content:center;
- align-items:center;
- margin-top: 4px;
- }
- }
- .action-item-right {
- margin-left: 40%;
- }
- }
- }
- .info {
- height: 30%;
- line-height: 16px;
- display: flex;
- align-items: center;
- .info-center {
- width: 100%;
- }
- .title {
- font-weight: bold;
- font-size: 16px;
- color: #303133;
- padding: 0 12px;
- justify-content: space-between;
- }
- .right {
- float: right;
- font-weight: normal;
- font-size: 14px;
- color: #909399;
- }
- .more {
- font-size: 16px;
- cursor: pointer;
- }
- .description {
- padding: 0 12px;
- font-size: 14px;
- color: #606266;
- margin-top: 10px;
- }
- }
- &.is-upload {
- box-shadow: none;
- border: 1px dashed #DCDFE6;
- }
- &.is-upload:hover {
- box-shadow: none;
- }
- &:hover {
- box-shadow: 0 0 10px 0 #999;
- .action {
- opacity: 1;
- }
- }
- }
- </style>
- <template>
- <section class="theme-card-item" :class="{'is-hidden': !config || !config.name, 'is-upload': isUpload}">
- <template v-if="isUpload">
- <div class="upload" @click="uploadClick">
- <div class="upload-action">
- <img src="../../assets/images/icon-upload.svg"/>
- <span>{{getActionDisplayName('upload-theme')}}</span>
- </div>
- </div>
- <input
- class="el-upload__input"
- type="file"
- ref="input"
- @change="uploadAction"
- accept="application/json"
- />
- </template>
- <template v-else>
- <div class="preview">
- <div class="line">
- <span class="line-2" :style="{background: mainColor}"></span>
- <span class="line-2" :style="{background: textPrimaryColor}"></span>
- </div>
- <div class="line">
- <span class="line-4" :style="{background: mainColor50}"></span>
- <span class="line-4" :style="{background: mainColor80}"></span>
- <span class="line-4" :style="{background: borderBaseColor}"></span>
- <span class="line-4" :style="{background: textSecondaryColor}"></span>
- </div>
- <div class="action">
- <div class="action-mask"></div>
- <div class="action-block">
- <div
- class="action-item"
- :class="index && 'action-item-right'"
- v-for="(item, index) in actionArray"
- :key="index"
- @click="iconClick(item.action)"
- >
- <div class="icon">
- <img :src="item.icon"/>
- <span class="circle"></span>
- </div>
- <div class="name">
- <span>{{item.name}}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="info">
- <div class="info-center">
- <div class="title">
- <span>{{config.name}}</span>
- <span class="right" v-if="isOfficial">by {{config.author}}</span>
- <span class="right more" v-else>
- <el-dropdown @command="actionClick">
- <i class="el-icon-more"></i>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item command="rename">{{getActionDisplayName('rename-theme')}}</el-dropdown-item>
- <el-dropdown-item command="copy">{{getActionDisplayName('copy-theme')}}</el-dropdown-item>
- <el-dropdown-item
- command="delete"
- style="color: #F56C6C;"
- >
- {{getActionDisplayName('delete-theme')}}
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </span>
- </div>
- <div class="description" v-if="isOfficial">{{getActionDisplayName(getDescriptionKey(config.name))}} </div>
- <div class="description" v-else>{{getActionDisplayName('last-modified')}} {{formatDate(config.update)}}</div>
- </div>
- </div>
- </template>
- </section>
- </template>
- <script>
- import bus from '../../bus';
- import {
- DEFAULT_THEME_CONFIG,
- ACTION_DOWNLOAD_THEME
- } from './constant.js';
- import { savePreviewToLocal } from './localstorage';
- import { tintColor } from '../../color.js';
- import dateUtil from 'element-ui/src/utils/date';
- import { getActionDisplayName } from '../theme-configurator/utils/utils';
- export default {
- props: {
- config: Object,
- type: String,
- base: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- deleteVisible: false
- };
- },
- methods: {
- getActionDisplayName(key) {
- return getActionDisplayName(key);
- },
- getDescriptionKey(name) {
- return name ? `description-${name.toLowerCase()}` : '';
- },
- formatDate(timestamp) {
- if (!timestamp) return '';
- return dateUtil.format(new Date(timestamp), 'yyyy-MM-dd HH:mm');
- },
- uploadClick() {
- this.$refs.input.value = null;
- this.$refs.input.click();
- },
- uploadAction(ev) {
- const files = ev.target.files;
- if (!files) return;
- var reader = new FileReader();
- reader.onload = (e) => {
- try {
- const jsonString = e.target.result;
- const jsonObject = JSON.parse(jsonString);
- if (!jsonObject.global || !jsonObject.local) {
- return this.$message.error('JSON format error');
- }
- this.$emit('action', 'upload', jsonString);
- } catch (e) {
- this.$message.error('Upload error');
- console.error(e);
- }
- };
- reader.readAsText(files[0]);
- },
- actionClick(e) {
- this.$emit('action', e, this.config);
- },
- iconClick(e) {
- switch (e) {
- case 'preview':
- case 'edit':
- const { name, theme } = this.config;
- savePreviewToLocal({
- type: this.type,
- name,
- theme
- });
- this.$router.push({
- name: `theme-preview-${this.$route.meta.lang}`,
- params: {
- refer: 'theme'
- }
- });
- this.$nextTick(() => {
- window.scrollTo(0, 0);
- });
- break;
- case 'download':
- bus.$emit(ACTION_DOWNLOAD_THEME, this.theme, this.config.name);
- break;
- default:
- this.$emit('action', e, this.config);
- return;
- }
- },
- deleteUserTheme() {
- this.deleteVisible = false;
- this.$emit('action', 'delete', this.config);
- }
- },
- computed: {
- isUpload() {
- return this.type === 'upload';
- },
- theme() {
- if (this.config.theme) {
- return JSON.parse(this.config.theme);
- }
- return DEFAULT_THEME_CONFIG;
- },
- mainColor() {
- return this.theme.global['$--color-primary'] || '#1989FA';
- },
- mainColor50() {
- return tintColor(this.mainColor, 0.5);
- },
- mainColor80() {
- return tintColor(this.mainColor, 0.8);
- },
- textPrimaryColor() {
- return this.theme.global['$--color-text-primary'] || '#303133';
- },
- borderBaseColor() {
- return this.theme.global['$--border-color-base'] || '#DCDFE6';
- },
- textSecondaryColor() {
- return this.theme.global['$--color-text-secondary'] || '#909399';
- },
- isOfficial() {
- return this.type === 'official';
- },
- actionArray() {
- if (this.isOfficial) {
- return [
- {
- icon: require('../../assets/images/icon-check.png'),
- name: getActionDisplayName('theme-check'),
- action: 'preview'
- },
- {
- icon: require('../../assets/images/icon-copy.png'),
- name: getActionDisplayName('theme-copy'),
- action: 'copy'
- }
- ];
- }
- return [
- {
- icon: require('../../assets/images/icon-edit.png'),
- name: getActionDisplayName('theme-edit'),
- action: 'edit'
- },
- {
- icon: require('../../assets/images/icon-download.png'),
- name: getActionDisplayName('download-theme'),
- action: 'download'
- }
- ];
- }
- }
- };
- </script>
|