CloudPhoneClipboard.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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">
  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. copyPasteVersiontext(e) {
  127. clickCopyText(e, (event) => {
  128. // TODO: 复制成功后发送消息给云机
  129. // this.doConnectDirectivesWs.send(JSON.stringify({
  130. // type: 'cutting',
  131. // data: {
  132. // str: event.text,
  133. // },
  134. // }))
  135. // this.$toast('复制成功')
  136. }, () => {
  137. Toast('复制失败')
  138. })
  139. },
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .pre {
  145. position: relative;
  146. }
  147. .pab {
  148. position: absolute;
  149. }
  150. .tc {
  151. text-align: center;
  152. }
  153. .ellipsis {
  154. overflow: hidden;
  155. text-overflow: ellipsis;
  156. white-space: nowrap;
  157. }
  158. .paste-version-modal {
  159. background-color: transparent;
  160. overflow: visible;
  161. ::v-deep .van-dialog__content {
  162. background-color: rgba(0, 0, 0, 0.6);
  163. display: flex;
  164. flex-direction: column;
  165. height: 270px;
  166. padding-bottom: 28px;
  167. border-radius: 16px;
  168. .paste-version-title {
  169. height: 48px;
  170. line-height: 48px;
  171. font-size: 16px;
  172. margin: 0 18px;
  173. &::-webkit-scrollbar {
  174. display: none;
  175. }
  176. & > span:first-child {
  177. top: 50%;
  178. left: 50%;
  179. transform: translate(-50%, -50%);
  180. color: #fff;
  181. }
  182. .paste-version-clear {
  183. position: absolute;
  184. top: 52%;
  185. transform: translateY(-52%);
  186. right: 0;
  187. height: 20px;
  188. line-height: 20px;
  189. padding: 0 10px;
  190. font-size: 12px;
  191. background: #3666f2;
  192. border-radius: 3px;
  193. color: #ffffff;
  194. }
  195. }
  196. .paste-version-list {
  197. flex: 1;
  198. overflow-y: auto;
  199. .van-swipe-cell {
  200. margin: 0 18px;
  201. box-sizing: border-box;
  202. height: 32px;
  203. line-height: 32px;
  204. text-align: center;
  205. font-size: 13px;
  206. color: #666;
  207. background-color: #fff;
  208. border-radius: 5px;
  209. overflow: hidden;
  210. .van-swipe-cell__wrapper {
  211. width: 100%;
  212. height: 100%;
  213. }
  214. .ellipsis {
  215. width: 100%;
  216. height: 100%;
  217. padding: 0 10px;
  218. box-sizing: border-box;
  219. }
  220. }
  221. .paste-version-delete {
  222. width: 40px;
  223. height: 100%;
  224. border: none;
  225. background: #f04646;
  226. color: #fff;
  227. font-size: 12px;
  228. text-align: center;
  229. border-radius: 0 5px 5px 0;
  230. }
  231. }
  232. .paste-version-close {
  233. width: 38px;
  234. height: 38px;
  235. bottom: -20%;
  236. left: 50%;
  237. transform: translateX(-50%);
  238. }
  239. .paste-version-empty img {
  240. width: 128px;
  241. height: 160px;
  242. }
  243. .paste-version-empty > div > div {
  244. margin-top: 9px;
  245. font-size: 15px;
  246. }
  247. }
  248. }
  249. </style>