|
@@ -1,13 +1,16 @@
|
|
|
<template>
|
|
|
- <el-button v-if="btnys" :class="columnCopyClass" type="info" size="mini">{{ text }}</el-button>
|
|
|
- <div v-else class="withinLine">
|
|
|
- <el-button :class="columnCopyClass" type="primary" size="mini">{{ text }}</el-button>
|
|
|
+ <el-button v-if="btnys && columnCopyClassKey" :class="columnCopyClassKey" type="info" size="mini">{{
|
|
|
+ text
|
|
|
+ }}</el-button>
|
|
|
+ <div v-else-if="columnCopyClassKey" class="withinLine">
|
|
|
+ <el-button :class="columnCopyClassKey" type="primary" size="mini">{{ text }}</el-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import buttonMixin from './button_mixin.js'
|
|
|
import ClipboardJS from 'clipboard'
|
|
|
+import md5 from 'md5'
|
|
|
var nrBR = `
|
|
|
`
|
|
|
export default {
|
|
@@ -34,6 +37,11 @@ export default {
|
|
|
default: false
|
|
|
}
|
|
|
},
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ columnCopyClassKey: 'name-' + this.getRandom16Chars(md5(this.columnCopyClass + '_' + this.orderInfo.id))
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted() {
|
|
|
this.textCopy()
|
|
|
},
|
|
@@ -43,6 +51,27 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ getRandom16Chars(str) {
|
|
|
+ // 确保输入字符串的长度是32
|
|
|
+ if (str.length !== 32) {
|
|
|
+ throw new Error('输入字符串必须是32个字符长')
|
|
|
+ }
|
|
|
+ // 创建一个存储选中的字符的数组
|
|
|
+ let selectedChars = []
|
|
|
+ // 使用 Set 来确保没有重复的索引
|
|
|
+ let indices = new Set()
|
|
|
+ // 随机选择16个不同的索引
|
|
|
+ while (indices.size < 10) {
|
|
|
+ let randomIndex = Math.floor(Math.random() * 32)
|
|
|
+ indices.add(randomIndex)
|
|
|
+ }
|
|
|
+ // 根据选中的索引提取字符
|
|
|
+ indices.forEach(index => {
|
|
|
+ selectedChars.push(str[index])
|
|
|
+ })
|
|
|
+ // 返回选中的16个字符组成的字符串
|
|
|
+ return selectedChars.join('')
|
|
|
+ },
|
|
|
// 组装复制内容
|
|
|
cpFormInfo() {
|
|
|
if (this.cpText) {
|
|
@@ -68,7 +97,7 @@ export default {
|
|
|
if (this.clipboard?.listener?.destroy) {
|
|
|
this.clipboard.listener.destroy()
|
|
|
}
|
|
|
- this.clipboard = new ClipboardJS(`.${this.columnCopyClass}`, {
|
|
|
+ this.clipboard = new ClipboardJS(`.${this.columnCopyClassKey}`, {
|
|
|
text: this.cpFormInfo
|
|
|
})
|
|
|
this.clipboard.on('success', () => {
|