MarkHeader.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <div class="flex items-center p-l-small p-r-base common-mark-header">
  3. <div class="flex items-center" style="margin-top: 3px">
  4. <div v-for="button in usedOperations" :key="button.type" class="btn-item">
  5. <div
  6. :ref="(el) => bindRef(button.type, el)"
  7. class="grid pointer radius-circle operation-button"
  8. :title="button.title"
  9. @click="onOperationClick(button)"
  10. >
  11. <svg-icon
  12. :name="attrs['icon-' + button.type] as string || 'mark-' + button.type"
  13. style="font-size: 18px"
  14. ></svg-icon>
  15. </div>
  16. <p class="icon-title">{{ button.smallTitle || button.title }}</p>
  17. </div>
  18. </div>
  19. <color-picker v-model="frontColor" :virtual-ref="refs['front-color']" virtual-triggering></color-picker>
  20. <color-picker v-model="backgroundColor" :virtual-ref="refs['background-color']" virtual-triggering></color-picker>
  21. <div class="flex flex-1 items-center mark-header">
  22. <slot></slot>
  23. <span class="data-item">
  24. <div class="icon-item">
  25. <lock-entry />
  26. </div>
  27. <div class="icon-item">
  28. <message :reply-user-id="props.replyUserId" :paper-path="props.paperPath"></message>
  29. </div>
  30. <div class="icon-item">
  31. <user-info></user-info>
  32. </div>
  33. </span>
  34. <!-- <div class="grid pointer close-icon" @click="willLogout">
  35. <el-icon><close /></el-icon>
  36. </div> -->
  37. </div>
  38. <!-- <base-dialog
  39. v-model="standardVisible"
  40. class="standard-dialog"
  41. :can-resize="'can-resize3'"
  42. title="评分标准"
  43. modal-class="no-mask"
  44. center
  45. :modal="false"
  46. >
  47. <div id="my-iframe-mask"></div>
  48. <iframe
  49. style="width: 100%; height: 100%; prevent-events: pointer"
  50. :src="
  51. standardRes?.url
  52. ? standardRes?.url + '#view=FitH&scrollbar=0&toolbar=0&statusbar=0&messages=0&navpanes=0'
  53. : ''
  54. "
  55. alt=""
  56. />
  57. </base-dialog> -->
  58. <standard-dialog v-model="standardVisible" :can-resize="'can-resize3'" resize-key="can-resize3"></standard-dialog>
  59. </div>
  60. </template>
  61. <script setup lang="ts" name="MarkHeader">
  62. import { reactive, ref, computed, useAttrs, watch, onUnmounted } from 'vue'
  63. import { useRoute } from 'vue-router'
  64. import { add, minus } from '@/utils/common'
  65. import useMainStore from '@/store/main'
  66. import SvgIcon from '@/components/common/SvgIcon.vue'
  67. import ColorPicker from '@/components/common/ColorPicker.vue'
  68. import Message from '@/components/shared/message/Message.vue'
  69. import UserInfo from '@/components/shared/UserInfo.vue'
  70. import { ElIcon, ElMessage } from 'element-plus'
  71. import { Close } from '@element-plus/icons-vue'
  72. import { logout } from '@/utils/shared'
  73. import { sessionStorage } from '@/plugins/storage'
  74. // import useFetch from '@/hooks/useFetch'
  75. import BaseDialog from '@/components/element/BaseDialog.vue'
  76. import LockEntry from '../common/LockEntry.vue'
  77. import StandardDialog from '@/components/shared/StandardDialog.vue'
  78. import bus from '@/utils/bus'
  79. type ButtonType =
  80. | 'back'
  81. | 'scale-up'
  82. | 'scale-down'
  83. | 'center'
  84. | 'rotate'
  85. | 'front-color'
  86. | 'background-color'
  87. | 'refresh'
  88. | 'remark'
  89. | 'problem'
  90. | 'example'
  91. | 'standard'
  92. | 'delete'
  93. | 'bookmark'
  94. interface HeaderButton {
  95. title: string
  96. type: ButtonType
  97. smallTitle?: string
  98. }
  99. type EventType = Exclude<ButtonType, 'scale-up' | 'scale-down'> | 'scale-change'
  100. const emits = defineEmits<{
  101. (e: 'click', opt: { type: EventType; value?: number | string | boolean | number[] }): void
  102. (e: EventType, val: any): void
  103. (e: 'back'): void
  104. (e: 'center', val: boolean): void
  105. (e: 'refresh'): void
  106. (e: 'remark'): void
  107. (e: 'problem'): void
  108. (e: 'example'): void
  109. (e: 'standard'): void
  110. (e: 'delete'): void
  111. (e: 'bookmark'): void
  112. (e: 'scale-change', val: number): void
  113. (e: 'rotate', val: number): void
  114. (e: 'front-color', color: number[]): void
  115. (e: 'background-color', color: number[]): void
  116. }>()
  117. const standardVisible = ref(false)
  118. const props = defineProps<{
  119. excludeOperations?: ButtonType[]
  120. includeOperations?: ButtonType[]
  121. replyUserId?: number | null
  122. paperPath?: string | null
  123. }>()
  124. const buttons: HeaderButton[] = [
  125. { title: '返回', type: 'back' },
  126. { title: '放大', type: 'scale-up' },
  127. { title: '缩小', type: 'scale-down' },
  128. { title: '居中', type: 'center' },
  129. { title: '旋转', type: 'rotate' },
  130. { title: '前景色', type: 'front-color' },
  131. { title: '背景色', type: 'background-color' },
  132. { title: '刷新', type: 'refresh' },
  133. { title: '回评', type: 'remark' },
  134. { title: '问题卷', type: 'problem' },
  135. { title: '查看样卷', type: 'example' },
  136. { title: '评分标准', type: 'standard' },
  137. { title: '删除当前专家卷', type: 'delete', smallTitle: '删除' },
  138. { title: '设置专家卷', type: 'bookmark', smallTitle: '设专家卷' },
  139. ]
  140. const refs = reactive<Partial<Record<ButtonType, Element>>>({
  141. 'front-color': void 0,
  142. 'background-color': void 0,
  143. })
  144. const bindRef = (type: ButtonType, el: any) => {
  145. if (el) {
  146. refs[type] = el
  147. }
  148. }
  149. const usedOperations = computed(() => {
  150. const viewButtons = props?.includeOperations
  151. ? buttons.filter((b) => props?.includeOperations?.some((t) => b.type === t))
  152. : buttons
  153. return viewButtons.filter((button) => !props.excludeOperations?.some((type) => button.type === type))
  154. })
  155. const attrs = useAttrs()
  156. const mainStore = useMainStore()
  157. const { fullPath } = useRoute()
  158. const userMarkConfig = computed(() => {
  159. return mainStore.userMarkConfig?.[fullPath]
  160. })
  161. /** center */
  162. const center = ref<boolean>(false)
  163. /** ratio */
  164. const ratio = ref<number>(1)
  165. /** rotate */
  166. const rotate = ref<number>(0)
  167. /** front-color */
  168. const frontColor = ref<string>('')
  169. /** background-color */
  170. const backgroundColor = ref<string>('')
  171. const saveMarkSet = () => {
  172. if (fullPath && !!sessionStorage.get('LOGIN_RESULT')) {
  173. mainStore.setUserMarkConfig({
  174. [fullPath]: {
  175. center: center.value,
  176. ratio: ratio.value,
  177. rotate: rotate.value,
  178. frontColor: frontColor.value,
  179. backgroundColor: backgroundColor.value,
  180. },
  181. })
  182. }
  183. }
  184. watch(center, () => emitEvent('center', center.value))
  185. watch(ratio, () => emitEvent('scale-change', ratio.value))
  186. watch(rotate, () => emitEvent('rotate', rotate.value))
  187. watch(frontColor, () => {
  188. emitEvent('front-color', frontColor.value)
  189. saveMarkSet()
  190. })
  191. watch(backgroundColor, () => {
  192. emitEvent('background-color', backgroundColor.value)
  193. saveMarkSet()
  194. })
  195. const validVal = (val: number, max: number, min: number) => {
  196. return Math.min(max, Math.max(val, min))
  197. }
  198. const onOperationClick = (button: HeaderButton) => {
  199. if (['front-color', 'background-color'].includes(button.type)) {
  200. return
  201. }
  202. switch (button.type) {
  203. case 'scale-up':
  204. ratio.value = validVal(add(ratio.value, 0.1), 2, 0.5)
  205. saveMarkSet()
  206. break
  207. case 'scale-down':
  208. ratio.value = validVal(minus(ratio.value, 0.1), 2, 0.5)
  209. saveMarkSet()
  210. break
  211. case 'rotate':
  212. rotate.value = (rotate.value + 90) % 360
  213. saveMarkSet()
  214. break
  215. case 'center':
  216. center.value = !center.value
  217. saveMarkSet()
  218. break
  219. default:
  220. emitEvent(button.type)
  221. // saveMarkSet()
  222. break
  223. }
  224. }
  225. function busEventHandler() {
  226. bus.on('scale-up', () => {
  227. ratio.value = validVal(add(ratio.value, 0.1), 2, 0.5)
  228. saveMarkSet()
  229. })
  230. bus.on('scale-down', () => {
  231. ratio.value = validVal(minus(ratio.value, 0.1), 2, 0.5)
  232. saveMarkSet()
  233. })
  234. bus.on('init-scale', () => {
  235. ratio.value = 1
  236. saveMarkSet()
  237. })
  238. }
  239. busEventHandler()
  240. const emitEvent = (type: EventType, val?: string | number | boolean | number[]) => {
  241. if (type === 'standard') {
  242. standardVisible.value = true
  243. return
  244. }
  245. if (type === 'refresh') {
  246. if (!mainStore.online) {
  247. ElMessage.error('您的网络已断开,请检查网络')
  248. return
  249. }
  250. }
  251. if (attrs['on' + type.replace(/^\S/, (s) => s.toUpperCase())]) {
  252. emits(type, val as any)
  253. }
  254. emits('click', { type: type, value: val })
  255. }
  256. type MarkConfig = {
  257. center: boolean
  258. ratio: number
  259. rotate: number
  260. frontColor: string
  261. backgroundColor: string
  262. }
  263. const setCurrentConfig = (config: MarkConfig) => {
  264. center.value = config.center ?? center.value
  265. ratio.value = config.ratio ?? ratio.value
  266. rotate.value = config.rotate ?? rotate.value
  267. frontColor.value = config.frontColor ?? frontColor.value
  268. backgroundColor.value = config.backgroundColor ?? backgroundColor.value
  269. }
  270. watch(
  271. userMarkConfig,
  272. () => {
  273. if (userMarkConfig.value) {
  274. setCurrentConfig(userMarkConfig.value)
  275. }
  276. },
  277. { immediate: true }
  278. )
  279. const willLogout = async () => {
  280. if (fullPath && !!sessionStorage.get('LOGIN_RESULT')) {
  281. await mainStore.setUserMarkConfig({
  282. [fullPath]: {
  283. center: center.value,
  284. ratio: ratio.value,
  285. rotate: rotate.value,
  286. frontColor: frontColor.value,
  287. backgroundColor: backgroundColor.value,
  288. },
  289. })
  290. logout()
  291. } else {
  292. logout()
  293. }
  294. }
  295. // onUnmounted(() => {
  296. // if (fullPath && !!sessionStorage.get('LOGIN_RESULT')) {
  297. // mainStore.setUserMarkConfig({
  298. // [fullPath]: {
  299. // center: center.value,
  300. // ratio: ratio.value,
  301. // rotate: rotate.value,
  302. // frontColor: frontColor.value,
  303. // backgroundColor: backgroundColor.value,
  304. // },
  305. // })
  306. // }
  307. // })
  308. </script>
  309. <style scoped lang="scss">
  310. .common-mark-header {
  311. height: $MainLayoutHeaderHeight;
  312. background-color: $MainLayoutHeaderBg;
  313. .btn-item {
  314. width: 60px;
  315. text-align: center;
  316. }
  317. .icon-title {
  318. font-size: 14px;
  319. transform: scale(0.9);
  320. color: #999;
  321. margin-top: 5px;
  322. }
  323. .operation-button {
  324. width: 40px;
  325. height: 40px;
  326. place-items: center;
  327. color: $RegularFontColor;
  328. background-color: rgba(255, 255, 255, 0.1);
  329. color: #fff;
  330. margin-left: auto;
  331. margin-right: auto;
  332. &:hover {
  333. background: $color--primary;
  334. color: $color--white;
  335. }
  336. }
  337. .mark-header {
  338. margin-left: auto;
  339. // color: $RegularFontColor;
  340. height: 100%;
  341. color: #999;
  342. font-size: $SmallFont;
  343. font-weight: bold;
  344. padding: 12px 0;
  345. ::v-deep(.data-item) {
  346. // padding-left: 20px;
  347. padding-left: 20px;
  348. padding-right: 20px;
  349. position: relative;
  350. height: 100%;
  351. display: flex;
  352. align-items: center;
  353. .icon-item {
  354. padding: 0 10px;
  355. }
  356. &:first-child {
  357. margin-left: auto;
  358. }
  359. &:not(:last-child) {
  360. &:after {
  361. content: '';
  362. position: absolute;
  363. right: 0;
  364. top: 0;
  365. width: 1px;
  366. height: 100%;
  367. background-color: #464646;
  368. }
  369. }
  370. // &:not(:last-child):after {
  371. // content: '';
  372. // margin-left: 20px;
  373. // display: inline-block;
  374. // width: 1px;
  375. // height: 16px;
  376. // vertical-align: middle;
  377. // background-color: #eeeeee;
  378. // }
  379. &.is-last:after {
  380. width: 0;
  381. }
  382. .main-ques-info {
  383. text-align: center;
  384. font-weight: bold;
  385. color: $color--primary;
  386. margin-bottom: 5px;
  387. max-width: 130px;
  388. }
  389. }
  390. .close-icon {
  391. width: 32px;
  392. height: 32px;
  393. margin-left: 10px;
  394. font-size: 1.4em;
  395. border-radius: 50%;
  396. place-items: center;
  397. color: #ccc;
  398. transition: all 0.3s ease-in-out;
  399. background-color: #222;
  400. &:hover {
  401. color: #fff;
  402. font-weight: bold;
  403. background-color: rgba(255, 255, 255, 0.1);
  404. }
  405. }
  406. }
  407. }
  408. </style>
  409. //
  410. <style lang="scss">
  411. // .standard-dialog {
  412. // display: flex;
  413. // flex-direction: column;
  414. // .el-dialog__body {
  415. // flex: 1;
  416. // padding: 2px !important;
  417. // position: relative;
  418. // max-height: 150vh !important;
  419. // }
  420. // .el-dialog__footer {
  421. // padding: 0 !important;
  422. // }
  423. // #my-iframe-mask {
  424. // position: absolute;
  425. // left: 0;
  426. // right: 0;
  427. // bottom: 0;
  428. // top: 0;
  429. // z-index: 10;
  430. // display: none;
  431. // }
  432. // }
  433. //
  434. </style>