card.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <div class="denet-toolbox" :class="{ 'pre-view': pre_view }">
  3. <div class="head">
  4. <span></span>
  5. <div v-show="state.show_btn && state.status == 'iframe'">
  6. <img :src="require('@/assets/svg/icon-iframe-fixed.svg')" alt class="fixed" @click="clickFixed" />
  7. <img :src="require('@/assets/svg/icon-iframe-full.svg')" alt class="full" @click="clickFull" />
  8. </div>
  9. </div>
  10. <div class="content" v-if="pre_view">
  11. <iframe :src="iframe_url" frameborder="0"></iframe>
  12. </div>
  13. <div class="content" v-else>
  14. <iframe :src="state.iframe_url" v-show="state.status == 'iframe'" ref="dom_iframe" frameborder="0"
  15. scrolling="yes" allow="camera *;microphone *"></iframe>
  16. <!-- sandbox="allow-same-origin allow-scripts allow-popups allow-top-navigation allow-forms allow-modals allow-popups-to-escape-sandbox" -->
  17. <!-- 网页错误 -->
  18. <div class="state" v-show="state.status == '网页错误'">
  19. <img :src="state.cover_url" alt="" class="cover" />
  20. <div class="info">
  21. <img :src="require('@/assets/svg/icon-iframe-error.svg')" alt />
  22. <div>Oops, this link is invalid</div>
  23. </div>
  24. </div>
  25. <!-- 加载 -->
  26. <div class="state" v-show="state.status == '加载'">
  27. <img :src="state.cover_url" alt="" class="cover" />
  28. <div class="info">
  29. <img :src="require('@/assets/svg/icon-iframe-loading.svg')" alt class="icon-loading" />
  30. </div>
  31. </div>
  32. <!-- 关闭 -->
  33. <div class="state" v-show="state.status == '关闭'">
  34. </div>
  35. <!-- 固定右上角 -->
  36. <div class="state" v-show="state.status == '固定右上角'">
  37. <div class="info">
  38. <img :src="require('@/assets/svg/icon-iframe-pinned.svg')" alt />
  39. <div class="pinned">Pinned to the top right</div>
  40. </div>
  41. </div>
  42. </div>
  43. <!-- alert -->
  44. <div class="alert" v-show="state.show_alert">
  45. <div class="back" @click.stop="clickCancel"></div>
  46. <div class="confirm">
  47. <div class="check">
  48. <input :id="state.checkbox_id" type='checkbox' v-model="state.checkbox" />
  49. <label :for="state.checkbox_id">Don't remind</label>
  50. </div>
  51. <div class="title">Web Page Progress May Reset</div>
  52. <div class="handle">
  53. <div class="cancel" @click.stop="clickCancel">Cancel</div>
  54. <div class="continue" @click.stop="clickContinue">Continue</div>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script setup>
  61. import { getChromeStorage, setChromeStorage, defineProps, sendChromeTabMessage } from "@/uilts/chromeExtension";
  62. import { getPostDetail } from '@/http/redPacket.js'
  63. import { guid, getQueryString } from "@/uilts/help";
  64. import { onMounted, reactive, ref } from "vue";
  65. let dom_area_iframe = ref(null)
  66. let state = reactive({
  67. status: '', //
  68. show_alert: false,
  69. show_btn: false,
  70. list: [],
  71. checkbox: false,
  72. checkbox_id: `denet-${guid()}`,
  73. postId: '',
  74. tweetId: '',
  75. detail: {},
  76. handle_type: '',
  77. cover_url: require('@/assets/img/back-loading.png')
  78. })
  79. let dom = {}
  80. let props = defineProps({
  81. pre_view: {
  82. type: Boolean,
  83. default: false,
  84. },
  85. iframe_url: {
  86. type: String,
  87. default: ''
  88. }
  89. })
  90. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  91. switch (req.actionType) {
  92. // 事件传输
  93. case 'Set_ToolBox_Fixed':
  94. if (req.data.tweetId == state.tweetId && req.data.type == '关闭') {
  95. state.show_btn = true
  96. state.status = 'iframe'
  97. state.iframe_url = req.data.iframe_url
  98. }
  99. break
  100. }
  101. })
  102. const clickContinue = () => {
  103. if (state.checkbox) {
  104. setChromeStorage({ fullCheck: JSON.stringify({ fullCheck: 1 }) })
  105. }
  106. if (state.handle_type == '全屏') {
  107. handleFull()
  108. } else {
  109. handleFixed()
  110. }
  111. state.show_alert = false
  112. }
  113. onMounted(() => {
  114. if (props.pre_view) {
  115. return
  116. }
  117. state.postId = getQueryString('postId')
  118. state.tweetId = getQueryString('tweetId')
  119. sendChromeTabMessage({
  120. actionType: 'Get_ToolBox_Fixed_TweetId'
  121. }, (res) => {
  122. if (res == state.tweetId) {
  123. state.status = '固定右上角'
  124. } else {
  125. state.status = '加载'
  126. getDetail()
  127. }
  128. })
  129. })
  130. let area_iframe
  131. const createIframe = () => {
  132. area_iframe = dom_area_iframe.value
  133. if (area_iframe.querySelector('iframe')) {
  134. return
  135. }
  136. let iframe = document.createElement('iframe')
  137. iframe.onerror = () => {
  138. state.status = '网页错误'
  139. }
  140. iframe.onload = () => {
  141. if (state.status == '加载' || state.status == 'iframe') {
  142. state.show_btn = true
  143. state.status = 'iframe'
  144. }
  145. }
  146. // if (state.detail.urlInBlacklist) {
  147. // iframe.sandbox = "allow-same-origin allow-scripts allow-popups allow-top-navigation allow-forms allow-modals allow-popups-to-escape-sandbox allow-presentation"
  148. // }
  149. // state.detail.convertUrl
  150. iframe.src = 'https://www.twitter.com'
  151. area_iframe.appendChild(iframe)
  152. }
  153. // detail函数
  154. const getDetail = () => {
  155. getPostDetail({
  156. params: {
  157. postId: state.postId
  158. }
  159. }).then((res) => {
  160. if (res && res.code == 0) {
  161. state.detail = JSON.parse(res.data.postBizData)
  162. console.log('postBizData', state.detail)
  163. // 加载iframe
  164. if (state.detail.viewBgImagePath) {
  165. state.cover_url = state.detail.viewBgImagePath
  166. }
  167. state.iframe_url = state.detail.convertUrl
  168. } else {
  169. state.status = '网页错误'
  170. }
  171. })
  172. }
  173. const clickCancel = () => {
  174. state.show_alert = false
  175. }
  176. const clickFixed = () => {
  177. state.handle_type = '固定右上角'
  178. getChromeStorage('fullCheck', (res) => {
  179. if (res && res.fullCheck) {
  180. // 固定
  181. handleFixed()
  182. } else {
  183. state.show_alert = true
  184. }
  185. })
  186. }
  187. // 固定
  188. const handleFull = () => {
  189. if (state.status != 'iframe' || !state.iframe_url) {
  190. return
  191. }
  192. // 切换状态
  193. state.status = '固定右上角'
  194. state.show_btn = false
  195. sendChromeTabMessage({
  196. actionType: 'Set_ToolBox_Fixed',
  197. data: {
  198. type: '全屏',
  199. iframe_url: state.iframe_url,
  200. tweetId: state.tweetId,
  201. }
  202. })
  203. // 清除当前iframe src
  204. state.iframe_url = ''
  205. }
  206. // 全屏
  207. const handleFixed = () => {
  208. // 切换状态
  209. state.show_btn = false
  210. state.status = '固定右上角'
  211. sendChromeTabMessage({
  212. actionType: 'Set_ToolBox_Fixed',
  213. data: {
  214. type: '固定右上角',
  215. iframe_url: state.iframe_url,
  216. tweetId: state.tweetId
  217. }
  218. })
  219. // 清除当前iframe src
  220. state.iframe_url = ''
  221. }
  222. const clickFull = () => {
  223. state.handle_type = '全屏'
  224. getChromeStorage('fullCheck', (res) => {
  225. if (res && res.fullCheck) {
  226. // 全屏
  227. handleFull()
  228. } else {
  229. state.show_alert = true
  230. }
  231. })
  232. }
  233. </script>
  234. <style lang="scss" >
  235. .pre-view {
  236. pointer-events: none;
  237. cursor: default;
  238. }
  239. .denet-toolbox {
  240. width: 100%;
  241. height: 100%;
  242. min-height: 100%;
  243. filter: drop-shadow(0px 4px 20px rgba(0, 0, 0, 0.2));
  244. border-radius: 12px;
  245. overflow: hidden;
  246. position: relative;
  247. .alert {
  248. text-align: center;
  249. position: absolute;
  250. top: 0;
  251. left: 0;
  252. width: 100%;
  253. height: 100%;
  254. .back {
  255. background: #000000;
  256. opacity: 0.8;
  257. position: absolute;
  258. top: 0;
  259. left: 0;
  260. width: 100%;
  261. height: 100%;
  262. cursor: auto;
  263. }
  264. .confirm {
  265. position: absolute;
  266. width: 355px;
  267. height: 180px;
  268. background: #FFFFFF;
  269. border-radius: 20px;
  270. top: 173px;
  271. left: 50%;
  272. margin-left: -180px;
  273. .title {
  274. font-weight: 600;
  275. font-size: 18px;
  276. color: #000000;
  277. margin-bottom: 34px;
  278. }
  279. .check {
  280. color: #899099;
  281. font-weight: 400;
  282. font-size: 14px;
  283. margin: 12px 15px 32px 0;
  284. text-align: right;
  285. align-content: center;
  286. justify-content: flex-end;
  287. display: flex;
  288. line-height: 17px;
  289. input {
  290. margin-right: 8px;
  291. }
  292. label {
  293. line-height: 19px;
  294. }
  295. }
  296. .handle {
  297. display: flex;
  298. justify-content: center;
  299. align-items: center;
  300. div {
  301. font-weight: 600;
  302. font-size: 16px;
  303. width: 156px;
  304. height: 47px;
  305. line-height: 47px;
  306. cursor: pointer;
  307. border-radius: 1000px;
  308. user-select: none;
  309. }
  310. .cancel {
  311. color: #000000;
  312. background: rgba(56, 154, 255, 0.01);
  313. border: 1px solid #E6E6E6;
  314. }
  315. .continue {
  316. background: #1D9BF0;
  317. font-weight: 600;
  318. margin-left: 11px;
  319. color: #FFFFFF;
  320. }
  321. }
  322. }
  323. }
  324. .head {
  325. width: 100%;
  326. height: 40px;
  327. background: #373737;
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. div {
  332. display: flex;
  333. justify-content: center;
  334. }
  335. span {
  336. color: #FFFFFF;
  337. font-style: normal;
  338. font-weight: 500;
  339. font-size: 14px;
  340. margin-left: 16px;
  341. }
  342. img {
  343. width: 20px;
  344. height: 20px;
  345. cursor: pointer;
  346. }
  347. .full {
  348. margin-right: 16px;
  349. }
  350. .fixed {
  351. margin-right: 20px;
  352. }
  353. }
  354. .content {
  355. width: 100%;
  356. height: calc(100% - 40px);
  357. background: #686868;
  358. display: flex;
  359. align-items: center;
  360. justify-content: center;
  361. .area-iframe {
  362. width: 100%;
  363. height: 100%;
  364. <<<<<<< HEAD iframe {
  365. background: #fff;
  366. width: 100%;
  367. height: 100%;
  368. border: medium none;
  369. }
  370. =======border: medium none;
  371. >>>>>>>dev_1.1.5-1
  372. }
  373. .state {
  374. text-align: center;
  375. width: 100%;
  376. height: 100%;
  377. position: relative;
  378. display: flex;
  379. justify-content: center;
  380. align-items: center;
  381. .cover {
  382. width: 100%;
  383. height: 100%;
  384. background: #000000;
  385. opacity: 0.6;
  386. }
  387. .icon-loading {
  388. animation: loading 1s infinite linear;
  389. }
  390. .info {
  391. position: absolute;
  392. width: 100%;
  393. height: 100%;
  394. top: 0;
  395. z-index: 1;
  396. display: flex;
  397. flex-wrap: wrap;
  398. flex-direction: column;
  399. justify-content: center;
  400. img {
  401. margin-bottom: 14px;
  402. }
  403. div {
  404. margin-bottom: 40px;
  405. color: #fff;
  406. text-align: center;
  407. font-weight: 500;
  408. font-size: 22px;
  409. }
  410. .pinned {
  411. color: #8E8E8E;
  412. }
  413. }
  414. }
  415. }
  416. }
  417. @keyframes loading {
  418. from {
  419. transform: rotate(0deg);
  420. }
  421. to {
  422. transform: rotate(360deg);
  423. }
  424. }
  425. </style>