CloudPhoneClipboard.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <van-dialog v-model="pasteVersionVisible" :show-confirm-button="false" class="paste-version-modal" v-cloak>
  3. <template v-if="pasteVersionList.length">
  4. <div class="tc paste-version-title pre">
  5. <span class="pab">粘贴版</span>
  6. <span class="pab paste-version-clear" @click="deletePasteVersion()"> 清空 </span>
  7. </div>
  8. <div class="paste-version-list">
  9. <div v-for="(item,index) in pasteVersionList" :key="index"
  10. :class="[{'mb-1': index!==pasteVersionList.length - 1}]">
  11. <van-swipe-cell>
  12. <div :class="`copy-value-${index}, ellipsis`" @click="copyPasteVersiontext(item.content)">
  13. {{item.content}}
  14. </div>
  15. <template #right>
  16. <div class="paste-version-delete" @click="deletePasteVersion(item.id)">删除</div>
  17. </template>
  18. </van-swipe-cell>
  19. </div>
  20. </div>
  21. </template>
  22. <template v-else>
  23. <div class="paste-version-empty flex-center-all h100">
  24. <div>
  25. <img :src="jianqieban" alt="">
  26. <div class="tc">剪贴板为空</div>
  27. </div>
  28. </div>
  29. </template>
  30. <img class="pab paste-version-close" :src="closePath" alt="" @click="pasteVersionVisible = false" />
  31. </van-dialog>
  32. </template>
  33. <script>
  34. import Qs from 'qs';
  35. export default {
  36. name: 'CloudPhoneClipboard',
  37. data() {
  38. return {
  39. jianqieban: '../rtcEngine/img/jianqieban_pic@2x.png',
  40. closePath: '../rtcEngine/img/guanbi_icon@2x.png',
  41. pasteVersionVisible: false, // 云机粘贴板弹窗
  42. pasteVersionList: [], // 粘贴板列表云机的粘贴板内容
  43. }
  44. },
  45. methods: {
  46. // 粘贴版相关接口
  47. shearContent({ type, params, queryStr }) {
  48. let url = '/public/v5/shear/content'
  49. if (queryStr) url += queryStr
  50. return this.$axios[`$${type}`](url, params);
  51. },
  52. // 内容植入云机的粘贴板
  53. init(text) {
  54. // 判断是否有内容, 有内容先把内容植入云机的粘贴板, 否则直接读取云机的粘贴板
  55. text ? this.openPasteboard(text) : this.getPasteVersion();
  56. },
  57. // 打开粘贴板
  58. async openPasteboard(content, callBack = () => {}) {
  59. try {
  60. await this.shearContent({ type: 'post', params: { content } });
  61. } catch (error) {
  62. console.log('error', error);
  63. } finally {
  64. callBack();
  65. // 获取剪切板
  66. this.getPasteVersion(() => {
  67. this.pasteVersionVisible = true;
  68. })
  69. }
  70. },
  71. // 获取云机粘贴板数据
  72. async getPasteVersion(callBack = () => {}) {
  73. try {
  74. const res = await this.shearContent({ type: 'get' });
  75. this.pasteVersionList = res.data;
  76. callBack(true)
  77. } catch (error) {
  78. callBack(false)
  79. }
  80. },
  81. // 清空全部 或 清除某条
  82. deletePasteVersion(ids){
  83. try {
  84. if (!ids) {
  85. this.$dialog.alert({
  86. title: '提示',
  87. message: '确定清空剪贴板?',
  88. confirmButtonText: '确定',
  89. confirmButtonColor: '#3cc51f',
  90. showCancelButton: true,
  91. beforeClose: (action, done) => {
  92. if (action === 'cancel') done()
  93. if (action === 'confirm') {
  94. fun.bind(this)(done)
  95. }
  96. }
  97. })
  98. return
  99. }
  100. fun.bind(this)()
  101. function fun(callBack = () => {}) {
  102. this.shearContent({
  103. type: 'delete',
  104. queryStr: Qs.stringify(
  105. { ids: ids ? [ids] : this.pasteVersionList.map((v) => v.id) },
  106. { arrayFormat: 'repeat', addQueryPrefix: true },
  107. )
  108. }).then(res => {
  109. if (res.status === 0) {
  110. // 删除成功后重新获取云机粘贴板数据
  111. this.getPasteVersion()
  112. callBack(true)
  113. } else {
  114. callBack(false)
  115. this.$toast(res.msg)
  116. }
  117. }).catch(() => {
  118. callBack(false)
  119. })
  120. }
  121. } catch (error) {
  122. console.log('error', error);
  123. }
  124. },
  125. // 复制粘贴某条数据
  126. async copyPasteVersiontext(text) {
  127. try {
  128. await this.$native.clipboard.writeText(text);
  129. this.$toast('复制成功')
  130. }catch (error) {
  131. console.log('error', error);
  132. this.$toast('复制失败')
  133. }
  134. },
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .pre {
  140. position: relative;
  141. }
  142. .pab {
  143. position: absolute;
  144. }
  145. .tc {
  146. text-align: center;
  147. }
  148. .ellipsis {
  149. overflow: hidden;
  150. text-overflow: ellipsis;
  151. white-space: nowrap;
  152. }
  153. .paste-version-modal {
  154. background-color: transparent;
  155. overflow: visible;
  156. ::v-deep .van-dialog__content {
  157. background-color: rgba(0, 0, 0, 0.6);
  158. display: flex;
  159. flex-direction: column;
  160. height: 270px;
  161. padding-bottom: 28px;
  162. border-radius: 16px;
  163. .paste-version-title {
  164. height: 48px;
  165. line-height: 48px;
  166. font-size: 16px;
  167. margin: 0 18px;
  168. &::-webkit-scrollbar {
  169. display: none;
  170. }
  171. & > span:first-child {
  172. top: 50%;
  173. left: 50%;
  174. transform: translate(-50%, -50%);
  175. color: #fff;
  176. }
  177. .paste-version-clear {
  178. position: absolute;
  179. top: 52%;
  180. transform: translateY(-52%);
  181. right: 0;
  182. height: 20px;
  183. line-height: 20px;
  184. padding: 0 10px;
  185. font-size: 12px;
  186. background: #3666f2;
  187. border-radius: 3px;
  188. color: #ffffff;
  189. }
  190. }
  191. .paste-version-list {
  192. flex: 1;
  193. overflow-y: auto;
  194. .van-swipe-cell {
  195. margin: 0 18px;
  196. box-sizing: border-box;
  197. height: 32px;
  198. line-height: 32px;
  199. text-align: center;
  200. font-size: 13px;
  201. color: #666;
  202. background-color: #fff;
  203. border-radius: 5px;
  204. overflow: hidden;
  205. .van-swipe-cell__wrapper {
  206. width: 100%;
  207. height: 100%;
  208. }
  209. .ellipsis {
  210. width: 100%;
  211. height: 100%;
  212. padding: 0 10px;
  213. box-sizing: border-box;
  214. }
  215. }
  216. .paste-version-delete {
  217. width: 40px;
  218. height: 100%;
  219. border: none;
  220. background: #f04646;
  221. color: #fff;
  222. font-size: 12px;
  223. text-align: center;
  224. border-radius: 0 5px 5px 0;
  225. }
  226. }
  227. .paste-version-close {
  228. width: 38px;
  229. height: 38px;
  230. bottom: -20%;
  231. left: 50%;
  232. transform: translateX(-50%);
  233. }
  234. .paste-version-empty img {
  235. width: 128px;
  236. height: 160px;
  237. }
  238. .paste-version-empty > div > div {
  239. margin-top: 9px;
  240. font-size: 15px;
  241. color: #fff;
  242. }
  243. }
  244. .flex-center-all{
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. }
  249. }
  250. </style>