mirror of
https://gitee.com/log4j/pig-ui.git
synced 2024-12-22 21:22:33 +08:00
clipboard切换为vue-clipboard3
This commit is contained in:
parent
b3a6bb6a8e
commit
6c28fb5211
@ -8,7 +8,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"clipboard": "^2.0.8",
|
|
||||||
"countup.js": "^2.0.7",
|
"countup.js": "^2.0.7",
|
||||||
"cropperjs": "^1.5.12",
|
"cropperjs": "^1.5.12",
|
||||||
"echarts": "^5.1.2",
|
"echarts": "^5.1.2",
|
||||||
@ -22,6 +21,7 @@
|
|||||||
"sortablejs": "^1.14.0",
|
"sortablejs": "^1.14.0",
|
||||||
"splitpanes": "^3.0.4",
|
"splitpanes": "^3.0.4",
|
||||||
"vue": "^3.0.11",
|
"vue": "^3.0.11",
|
||||||
|
"vue-clipboard3": "^1.0.1",
|
||||||
"vue-grid-layout": "^3.0.0-beta1",
|
"vue-grid-layout": "^3.0.0-beta1",
|
||||||
"vue-i18n": "^9.1.4",
|
"vue-i18n": "^9.1.4",
|
||||||
"vue-router": "^4.0.8",
|
"vue-router": "^4.0.8",
|
||||||
|
@ -356,7 +356,7 @@
|
|||||||
icon="el-icon-document-copy"
|
icon="el-icon-document-copy"
|
||||||
type="primary"
|
type="primary"
|
||||||
ref="copyConfigBtnRef"
|
ref="copyConfigBtnRef"
|
||||||
@click="onCopyConfigClick($event.target)"
|
@click="onCopyConfigClick"
|
||||||
>{{ $t('message.layout.copyText') }}
|
>{{ $t('message.layout.copyText') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
@ -366,22 +366,19 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { nextTick, onUnmounted, onMounted, getCurrentInstance, defineComponent, computed, ref } from 'vue';
|
import { nextTick, onUnmounted, onMounted, getCurrentInstance, defineComponent, computed } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
|
||||||
import ClipboardJS from 'clipboard';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
import { useStore } from '/@/store/index';
|
import { useStore } from '/@/store/index';
|
||||||
import { getLightColor } from '/@/utils/theme';
|
import { getLightColor } from '/@/utils/theme';
|
||||||
import Watermark from '/@/utils/wartermark';
|
import Watermark from '/@/utils/wartermark';
|
||||||
import { verifyAndSpace } from '/@/utils/toolsValidate';
|
import { verifyAndSpace } from '/@/utils/toolsValidate';
|
||||||
import { Local } from '/@/utils/storage';
|
import { Local } from '/@/utils/storage';
|
||||||
|
import commonFunction from '/@/utils/commonFunction.ts';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'layoutBreadcrumbSeting',
|
name: 'layoutBreadcrumbSeting',
|
||||||
setup() {
|
setup() {
|
||||||
const { t } = useI18n();
|
|
||||||
const { proxy } = getCurrentInstance() as any;
|
const { proxy } = getCurrentInstance() as any;
|
||||||
const copyConfigBtnRef = ref();
|
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
const { copyText } = commonFunction();
|
||||||
// 获取布局配置信息
|
// 获取布局配置信息
|
||||||
const getThemeConfig = computed(() => {
|
const getThemeConfig = computed(() => {
|
||||||
return store.state.themeConfig.themeConfig;
|
return store.state.themeConfig.themeConfig;
|
||||||
@ -557,10 +554,6 @@ export default defineComponent({
|
|||||||
// 布局配置弹窗打开
|
// 布局配置弹窗打开
|
||||||
const openDrawer = () => {
|
const openDrawer = () => {
|
||||||
getThemeConfig.value.isDrawer = true;
|
getThemeConfig.value.isDrawer = true;
|
||||||
nextTick(() => {
|
|
||||||
// 初始化复制功能,防止点击两次才可以复制
|
|
||||||
onCopyConfigClick(copyConfigBtnRef.value.$el);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
// 触发 store 布局配置更新
|
// 触发 store 布局配置更新
|
||||||
const setDispatchThemeConfig = () => {
|
const setDispatchThemeConfig = () => {
|
||||||
@ -577,20 +570,11 @@ export default defineComponent({
|
|||||||
Local.set('themeConfigStyle', document.documentElement.style.cssText);
|
Local.set('themeConfigStyle', document.documentElement.style.cssText);
|
||||||
};
|
};
|
||||||
// 一键复制配置
|
// 一键复制配置
|
||||||
const onCopyConfigClick = (target: any) => {
|
const onCopyConfigClick = () => {
|
||||||
let copyThemeConfig = Local.get('themeConfig');
|
let copyThemeConfig = Local.get('themeConfig');
|
||||||
copyThemeConfig.isDrawer = false;
|
copyThemeConfig.isDrawer = false;
|
||||||
const clipboard = new ClipboardJS(target, {
|
copyText(JSON.stringify(copyThemeConfig)).then(() => {
|
||||||
text: () => JSON.stringify(copyThemeConfig),
|
|
||||||
});
|
|
||||||
clipboard.on('success', () => {
|
|
||||||
getThemeConfig.value.isDrawer = false;
|
getThemeConfig.value.isDrawer = false;
|
||||||
ElMessage.success(t('message.layout.copyTextSuccess'));
|
|
||||||
clipboard.destroy();
|
|
||||||
});
|
|
||||||
clipboard.on('error', () => {
|
|
||||||
ElMessage.error(t('message.layout.copyTextError'));
|
|
||||||
clipboard.destroy();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 修复防止退出登录再进入界面时,需要刷新样式才生效的问题,初始化布局样式等(登录的时候触发,目前方案)
|
// 修复防止退出登录再进入界面时,需要刷新样式才生效的问题,初始化布局样式等(登录的时候触发,目前方案)
|
||||||
@ -668,7 +652,6 @@ export default defineComponent({
|
|||||||
onClassicSplitMenuChange,
|
onClassicSplitMenuChange,
|
||||||
onIsBreadcrumbChange,
|
onIsBreadcrumbChange,
|
||||||
onSortableTagsViewChange,
|
onSortableTagsViewChange,
|
||||||
copyConfigBtnRef,
|
|
||||||
onCopyConfigClick,
|
onCopyConfigClick,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
65
src/utils/commonFunction.ts
Normal file
65
src/utils/commonFunction.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// 通用函数
|
||||||
|
import useClipboard from 'vue-clipboard3';
|
||||||
|
import { ElMessage } from 'element-plus';
|
||||||
|
import { formatDate } from '/@/utils/formatTime';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
|
export default function () {
|
||||||
|
const { t } = useI18n();
|
||||||
|
const { toClipboard } = useClipboard();
|
||||||
|
//百分比格式化
|
||||||
|
const percentFormat = (row: any, column: number, cellValue: any) => {
|
||||||
|
return cellValue ? `${cellValue}%` : '-';
|
||||||
|
};
|
||||||
|
//列表日期时间格式化
|
||||||
|
const dateFormatYMD = (row: any, column: number, cellValue: any) => {
|
||||||
|
if (!cellValue) return '-';
|
||||||
|
return formatDate(new Date(cellValue), 'YYYY-mm-dd');
|
||||||
|
};
|
||||||
|
//列表日期时间格式化
|
||||||
|
const dateFormatYMDHMS = (row: any, column: number, cellValue: any) => {
|
||||||
|
if (!cellValue) return '-';
|
||||||
|
return formatDate(new Date(cellValue), 'YYYY-mm-dd HH:MM:SS');
|
||||||
|
};
|
||||||
|
//列表日期时间格式化
|
||||||
|
const dateFormatHMS = (row: any, column: number, cellValue: any) => {
|
||||||
|
if (!cellValue) return '-';
|
||||||
|
let time = 0;
|
||||||
|
if (typeof row === 'number') time = row;
|
||||||
|
if (typeof cellValue === 'number') time = cellValue;
|
||||||
|
return formatDate(new Date(time * 1000), 'HH:MM:SS');
|
||||||
|
};
|
||||||
|
// 小数格式化
|
||||||
|
const scaleFormat = (value: any = 0, scale: number = 4) => {
|
||||||
|
return Number.parseFloat(value).toFixed(scale);
|
||||||
|
};
|
||||||
|
// 小数格式化
|
||||||
|
const scale2Format = (value: any = 0) => {
|
||||||
|
return Number.parseFloat(value).toFixed(2);
|
||||||
|
};
|
||||||
|
// 点击复制文本
|
||||||
|
const copyText = (text: string) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
//复制
|
||||||
|
toClipboard(text);
|
||||||
|
//下面可以设置复制成功的提示框等操作
|
||||||
|
ElMessage.success(t('message.layout.copyTextSuccess'));
|
||||||
|
resolve(text);
|
||||||
|
} catch (e) {
|
||||||
|
//复制失败
|
||||||
|
ElMessage.error(t('message.layout.copyTextError'));
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
percentFormat,
|
||||||
|
dateFormatYMD,
|
||||||
|
dateFormatYMDHMS,
|
||||||
|
dateFormatHMS,
|
||||||
|
scaleFormat,
|
||||||
|
scale2Format,
|
||||||
|
copyText,
|
||||||
|
};
|
||||||
|
}
|
@ -2,14 +2,14 @@
|
|||||||
<div id="printRref">
|
<div id="printRref">
|
||||||
<el-card shadow="hover" header="复制剪切演示">
|
<el-card shadow="hover" header="复制剪切演示">
|
||||||
<el-alert
|
<el-alert
|
||||||
title="感谢优秀的 `clipboard`,项目地址:https://github.com/zenorocha/clipboard.js`"
|
title="感谢优秀的 `vue-clipboard3`,项目地址:https://github.com/JamieCurnow/vue-clipboard3`"
|
||||||
type="success"
|
type="success"
|
||||||
:closable="false"
|
:closable="false"
|
||||||
class="mb15"
|
class="mb15"
|
||||||
></el-alert>
|
></el-alert>
|
||||||
<el-input placeholder="请输入内容" v-model="copyVal">
|
<el-input placeholder="请输入内容" v-model="copyVal">
|
||||||
<template #append>
|
<template #append>
|
||||||
<el-button @click="onCopyClick($event.target)" ref="copyBtnRef">复制链接</el-button>
|
<el-button @click="copyText(copyVal)">复制链接</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-input>
|
</el-input>
|
||||||
<el-input placeholder="先点击上方 `复制链接` 按钮,然后 `Ctrl + V` 进行粘贴! " v-model="shearVal" class="mt15"> </el-input>
|
<el-input placeholder="先点击上方 `复制链接` 按钮,然后 `Ctrl + V` 进行粘贴! " v-model="shearVal" class="mt15"> </el-input>
|
||||||
@ -18,43 +18,20 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { reactive, toRefs, ref, onMounted, nextTick } from 'vue';
|
import { reactive, toRefs, onMounted } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import commonFunction from '/@/utils/commonFunction.ts';
|
||||||
import ClipboardJS from 'clipboard';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
|
||||||
export default {
|
export default {
|
||||||
name: 'funClipboard',
|
name: 'funClipboard',
|
||||||
setup() {
|
setup() {
|
||||||
const { t } = useI18n();
|
const { copyText } = commonFunction();
|
||||||
const copyBtnRef = ref();
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
copyVal: 'https://gitee.com/lyt-top/vue-next-admin',
|
copyVal: 'https://gitee.com/lyt-top/vue-next-admin',
|
||||||
shearVal: '',
|
shearVal: '',
|
||||||
});
|
});
|
||||||
// 复制链接点击
|
|
||||||
const onCopyClick = (target: any) => {
|
|
||||||
const clipboard = new ClipboardJS(target, {
|
|
||||||
text: () => state.copyVal,
|
|
||||||
});
|
|
||||||
clipboard.on('success', () => {
|
|
||||||
ElMessage.success(t('message.layout.copyTextSuccess'));
|
|
||||||
clipboard.destroy();
|
|
||||||
});
|
|
||||||
clipboard.on('error', () => {
|
|
||||||
ElMessage.error(t('message.layout.copyTextError'));
|
|
||||||
clipboard.destroy();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
// 页面加载时
|
// 页面加载时
|
||||||
onMounted(() => {
|
onMounted(() => {});
|
||||||
nextTick(() => {
|
|
||||||
// 初始化复制功能,防止点击两次才可以复制
|
|
||||||
onCopyClick(copyBtnRef.value.$el);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
copyBtnRef,
|
copyText,
|
||||||
onCopyClick,
|
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user