MarkHeader.vue 11 KB

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