MarkHeader.vue 13 KB

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