CloudPhoneClipboard.vue 6.8 KB

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