ss-index-components.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. import { isNum, toStyleStr } from "./tools.js";
  2. import { eventBus, EVEN_VAR } from "./EventBus.js";
  3. // import { debounce } from "../lib/tools.js";
  4. // 首页组件的名字
  5. const winName = {
  6. launch: "launch",
  7. Notice: "Notice",
  8. Statistics: "Statistics",
  9. TodoList: "TodoList",
  10. UrgingList: "UrgingList",
  11. UserInfo: "UserInfo",
  12. };
  13. // 尺寸窗口名字
  14. const size2Win = (name) => `${name}-${document.body.clientWidth}`;
  15. // 加载尺寸
  16. const loadWinSize = function (name) {
  17. const val = localStorage.getItem(size2Win(name));
  18. if (val) {
  19. try {
  20. return JSON.parse(val) || {};
  21. } catch (err) {
  22. return {};
  23. }
  24. } else {
  25. return {};
  26. }
  27. };
  28. const saveWinSize = function (name, obj) {
  29. localStorage.setItem(size2Win(name), JSON.stringify(obj));
  30. };
  31. // 全局头部
  32. export const GlobalHeader = {
  33. name: 'GlobalHeader',
  34. props: {
  35. menuData: {
  36. type: Array,
  37. required: true
  38. },
  39. iconItems: {
  40. type: Array,
  41. required: true
  42. }
  43. },
  44. setup(props) {
  45. //原值为'/newUI/skin/easy/images/logo/full-logo.png' Ben(20251205)
  46. const fullLogo = Vue.ref('/skin/easy/images/logo/full-logo.png'); // 需要指定完整路径
  47. const convertMenuData = (menuData) => {
  48. return menuData.map(item => ({
  49. id: item.id, //菜单id
  50. pid: item.pid, //父菜单id
  51. label: item.desc, //菜单名称
  52. component: item.url, //菜单链接
  53. js: item.js, //菜单要执行的js
  54. class: item.icon, // 如果icon为空则使用默认class
  55. itemType: item.type, //菜单 1:菜单项 2:菜单组
  56. }));
  57. };
  58. const menuItemsNew = Vue.ref(convertMenuData(props.menuData));
  59. Vue.watchEffect(() => {
  60. if (props.menuData && props.menuData.length) {
  61. menuItemsNew.value = convertMenuData(props.menuData);
  62. console.log('Header menu items updated:', menuItemsNew.value);
  63. }
  64. });
  65. const menuItems = Vue.ref([]);
  66. const breadCrumbs = Vue.ref([
  67. { label: '首页', component: '/index.html' },
  68. ]);
  69. const iconItems = Vue.ref(props.iconItems);
  70. const onClickMenuItemsNew = (item) => {
  71. console.log(item.component, item.js)
  72. if (item.component && item.js) {
  73. eval(item.js)
  74. } else if(item.component){
  75. eventBus.publish(EVEN_VAR.currentPage, item.component);
  76. } else {
  77. eval(item.js)
  78. }
  79. };
  80. const onClickMenuItem = (item) => {
  81. if (item.type == 'page') {
  82. eventBus.publish(EVEN_VAR.currentPage, item.component);
  83. breadCrumbs.value[0] = item
  84. } else if (item.type == 'dialog') {
  85. SS.openDialog({
  86. headerTitle: item.label,
  87. src: '.'+item.component,
  88. height: item.height,
  89. width:item.width
  90. });
  91. }
  92. };
  93. const breadCrumbClick = (item) => {
  94. eventBus.publish(EVEN_VAR.currentPage, item.component);
  95. breadCrumbs.value[0] = item
  96. }
  97. const gotoSearch = () => {
  98. eventBus.publish(EVEN_VAR.showGlobalSearchDialog);
  99. };
  100. const SsIcon = Vue.resolveComponent('ss-icon');
  101. const SsHeaderIcon = Vue.resolveComponent('ss-header-icon');
  102. const SsGolbalMenuIcon = Vue.resolveComponent('ss-golbal-menu-icon');
  103. // 引入搜索框
  104. const SsSearch = Vue.resolveComponent('ss-search');
  105. // 处理面包屑导航
  106. const renderBreadcrumbs = () => {
  107. const breadcrumbElements = [Vue.h(SsIcon, { class: "home-icon", name: "home", type: "common", size: "22px" })];
  108. // 遍历面包屑数组,添加面包屑和分隔符
  109. breadCrumbs.value.forEach((crumb, index) => {
  110. // 添加面包屑链接
  111. breadcrumbElements.push(
  112. Vue.h('span', { onClick: () => breadCrumbClick(crumb) }, crumb.label)
  113. );
  114. // 除了最后一个元素,每个面包屑后添加分隔符图标
  115. if (index < breadCrumbs.value.length - 1) {
  116. breadcrumbElements.push(
  117. Vue.h(SsIcon, { class: "split-icon", size: "12px", name: "double-arrow-right", type: "common" })
  118. );
  119. }
  120. });
  121. return breadcrumbElements;
  122. };
  123. return () => Vue.h('div', { class: 'block-self flex-between-center global-header-container' }, [
  124. Vue.h('div', { class: 'icon-area flex-start-center' }, [
  125. Vue.h('div', { class: 'logo', onClick: () => console.log('Home clicked') }, [
  126. Vue.h('div', { class: 'img' }, [
  127. Vue.h('img', { src: fullLogo.value })
  128. ]),
  129. Vue.h('div', { class: 'menu', onClick: Vue.withModifiers(() => { }, ['stop']) },
  130. // menuItems.value.map(item =>
  131. // Vue.h('div', { onClick: () => onClickMenuItem(item) },[
  132. // Vue.h(SsGolbalMenuIcon, { class: item.class || '' }),
  133. // item.label
  134. // ])
  135. // )
  136. menuItemsNew.value.map(item =>
  137. Vue.h('div', { onClick: () => onClickMenuItemsNew(item) },[
  138. Vue.h(SsGolbalMenuIcon, { class: item.class || '' }),
  139. item.label
  140. ])
  141. )
  142. )
  143. ]),
  144. // Vue.h('div', { class: 'bread-crumb', style: { height: "100% !important" } }, [
  145. // Vue.h('div', { class: 'content' }, renderBreadcrumbs())
  146. // ])
  147. ]),
  148. Vue.h('div', { class: 'menu-area' },
  149. Vue.h('div', { class: 'search-area' }, [
  150. Vue.h(SsSearch, { theme: 'dark', placeholder: '跨对象搜索', onClick: gotoSearch })
  151. ]),
  152. iconItems.value.map(icon =>
  153. Vue.h('div', { class: 'icon-item', onClick: icon.action, style: { display: icon.condition ? (icon.condition() ? 'block' : 'none') : 'block' } }, [
  154. Vue.h(SsHeaderIcon, { class: icon.class })
  155. ])
  156. )
  157. )
  158. ]);
  159. }
  160. };
  161. // 全局菜单
  162. export const GlobalMenu = {
  163. name: 'GlobalMenu',
  164. props: {
  165. menuItems: {
  166. type: Array,
  167. required: true
  168. },
  169. initialSize: {
  170. type: String,
  171. default: 'min'
  172. },
  173. // onMenuClick: {
  174. // type: Function,
  175. // required: true,
  176. // default: () => {}
  177. // }
  178. },
  179. setup(props) {
  180. const menuItemsNew = Vue.ref([]);
  181. const activeItem = Vue.ref(''); // 默认选中第一个菜单项
  182. // 将后台返回的菜单数据转换为树结构
  183. const convertMenuDataToTree = (menuData) => {
  184. // 先转换格式
  185. const formattedData = menuData.map(item => ({
  186. id: item.id,
  187. pid: item.pid,
  188. name: item.desc,
  189. component: item.url,
  190. js: item.js,
  191. class: item.type == 1 ? 'nav-icon-folder-close' : item.icon || 'header-home',
  192. itemType: item.type,
  193. children: []
  194. }));
  195. // 创建一个映射表,方便查找
  196. const map = {};
  197. formattedData.forEach(item => {
  198. map[item.id] = item;
  199. });
  200. // 构建树结构
  201. const treeData = [];
  202. formattedData.forEach(item => {
  203. if (item.pid && map[item.pid]) {
  204. // 如果有父节点,就放到父节点的children中
  205. if (!map[item.pid].children) {
  206. map[item.pid].children = [];
  207. }
  208. map[item.pid].children.push(item);
  209. } else {
  210. // 没有父节点就是顶层节点
  211. treeData.push(item);
  212. }
  213. });
  214. return treeData;
  215. };
  216. // 添加 watchEffect 来监听 props.menuItems 的变化
  217. Vue.watchEffect(() => {
  218. if (props.menuItems && props.menuItems.length) {
  219. menuItemsNew.value = convertMenuDataToTree(props.menuItems);
  220. // 初始化 activeItem
  221. const firstItem = menuItemsNew.value[0];
  222. if(firstItem?.component){
  223. // 首页有URL,直接设置为首页
  224. activeItem.value = firstItem.name;
  225. eventBus.publish(EVEN_VAR.currentPage, firstItem.component);
  226. } else if(firstItem?.children && firstItem.children.length > 0){
  227. // 首页没有URL,但有子菜单,设置为第一个子菜单
  228. activeItem.value = firstItem.children[0].name;
  229. eventBus.publish(EVEN_VAR.currentPage, firstItem.children[0].component);
  230. } else {
  231. activeItem.value = '';
  232. }
  233. console.log('Menu items updated:', menuItemsNew.value);
  234. }
  235. });
  236. const SsIcon = Vue.resolveComponent('ss-icon');
  237. const SsNavIcon = Vue.resolveComponent('ss-nav-icon');
  238. // 移动状态控制逻辑到组件内
  239. const leftSideTypeDict = {
  240. min: { key: "min", icon: "arrow-double-right" },
  241. max: { key: "max", icon: "arrow-double-left" },
  242. };
  243. const leftSideType = Vue.ref(leftSideTypeDict[props.initialSize]);
  244. let waitLeftSideChangeTimer = null;
  245. // 控制子菜单展开状态
  246. const expandedMenus = Vue.ref(new Set());
  247. // 点击子菜单不高亮父菜单 by xu 20251211
  248. const shouldHighlightMenu = (item) => {
  249. if (!item) {
  250. return false;
  251. }
  252. const hasChildren = Array.isArray(item.children) && item.children.length > 0;
  253. return !hasChildren && activeItem.value === item.name;
  254. };
  255. // ===== 三种菜单模式管理 =====
  256. const menuModeDict = {
  257. collapse: { key: "collapse", label: "收起", width: "60px" },
  258. fixed: { key: "fixed", label: "固定", width: "60px" },
  259. expand: { key: "expand", label: "展开", width: "230px" }
  260. };
  261. // 当前菜单模式(默认收起)
  262. const currentMenuMode = Vue.ref(menuModeDict.collapse);
  263. // 切换菜单模式(循环:收起 → 固定 → 展开 → 收起)
  264. const toggleMenuMode = () => {
  265. const modeOrder = ['collapse', 'fixed', 'expand'];
  266. const currentIndex = modeOrder.indexOf(currentMenuMode.value.key);
  267. const nextIndex = (currentIndex + 1) % modeOrder.length;
  268. const nextMode = menuModeDict[modeOrder[nextIndex]];
  269. currentMenuMode.value = nextMode;
  270. // 更新 CSS 变量
  271. updateLayoutWidth(nextMode.width);
  272. };
  273. // 更新布局宽度
  274. const updateLayoutWidth = (width) => {
  275. const layoutContainer = document.querySelector('.layout-container');
  276. if (layoutContainer) {
  277. layoutContainer.style.setProperty('--left-side-width', width);
  278. }
  279. };
  280. const onMenuClick = (item) => {
  281. console.log(item)
  282. console.log(activeItem.value)
  283. if(item.component && item.js){
  284. eval(item.js)
  285. } else if(item.component){
  286. eventBus.publish(EVEN_VAR.currentPage, item.component);
  287. }else{
  288. eval(item.js)
  289. }
  290. }
  291. const toggleLeftSideType = () => {
  292. leftSideType.value =
  293. leftSideType.value.key === 'min' ? leftSideTypeDict.max : leftSideTypeDict.min;
  294. };
  295. const doChangeLeftSideType2Max = () => {
  296. // 只有在收起模式下才响应鼠标悬停
  297. if (currentMenuMode.value.key === 'collapse' && leftSideType.value.key === 'min') {
  298. // 即刻展开,不需要延迟
  299. clearTimeout(waitLeftSideChangeTimer);
  300. leftSideType.value = leftSideTypeDict.max;
  301. }
  302. };
  303. const onLeaveLeftMenuArea = () => {
  304. // 只有在收起模式下才响应鼠标离开
  305. if (currentMenuMode.value.key === 'collapse') {
  306. if (waitLeftSideChangeTimer) {
  307. clearTimeout(waitLeftSideChangeTimer);
  308. waitLeftSideChangeTimer = null;
  309. }
  310. leftSideType.value = leftSideTypeDict.min;
  311. }
  312. };
  313. return () => Vue.h('div', { class: 'left-side' }, [
  314. Vue.h('div', {
  315. class: 'left-side-container',
  316. 'data-mode': currentMenuMode.value.key, // 添加模式标识
  317. size: leftSideType.value.key
  318. }, [
  319. // ===== 固定区域:首页 =====
  320. Vue.h('div', { class: 'fixed-top' }, [
  321. menuItemsNew.value.length > 0 ? Vue.h('div', {
  322. class: ['menu-item', 'level-1', { active: shouldHighlightMenu(menuItemsNew.value[0]) }],
  323. onClick: () => {
  324. const firstItem = menuItemsNew.value[0];
  325. activeItem.value = firstItem.name;
  326. onMenuClick(firstItem);
  327. }
  328. }, [
  329. Vue.h('div', { class: 'menu-item-content' }, [
  330. Vue.h(SsNavIcon, { class: menuItemsNew.value[0]?.class || 'nav-icon-home' }),
  331. Vue.h('div', { class: 'menu-item-label' }, menuItemsNew.value[0]?.name || '首页')
  332. ])
  333. ]) : null
  334. ]),
  335. // ===== 可滚动区域:其他菜单项 =====
  336. Vue.h('div', {
  337. class: 'scrollable-content',
  338. onMouseenter: doChangeLeftSideType2Max,
  339. onMousemove: doChangeLeftSideType2Max,
  340. onMouseleave: onLeaveLeftMenuArea
  341. }, [
  342. // 菜单项列表(跳过首页)
  343. ...menuItemsNew.value.slice(1).map(icon => [
  344. // 父菜单项
  345. Vue.h('div', {
  346. class: ['menu-item', 'level-1', { active: shouldHighlightMenu(icon) }],
  347. onClick: () => {
  348. if (icon.children && icon.children.length > 0) {
  349. // 有子菜单:仅切换展开/收起,不设置 activeItem(不高亮)
  350. if (expandedMenus.value.has(icon.name)) {
  351. expandedMenus.value.delete(icon.name);
  352. } else {
  353. expandedMenus.value.add(icon.name);
  354. }
  355. } else {
  356. // 无子菜单:设置 activeItem 并导航
  357. activeItem.value = icon.name;
  358. onMenuClick(icon);
  359. }
  360. }
  361. }, [
  362. Vue.h('div', { class: 'menu-item-content' }, [
  363. Vue.h(SsNavIcon, {
  364. // 如果是文件夹类型(type == 1),根据展开状态设置不同的class
  365. class: icon.itemType == 1 ?
  366. (expandedMenus.value.has(icon.name) ? 'nav-icon-folder-open' : 'nav-icon-folder-close')
  367. : (icon.class || '')
  368. }),
  369. Vue.h('div', { class: 'menu-item-label' }, icon.name || ''),
  370. // 有子菜单时显示小圆点(在一级菜单右上角)
  371. icon.children && icon.children.length > 0 ?
  372. Vue.h('div', { class: 'has-children-dot' }) : null
  373. ])
  374. ]),
  375. // 子菜单项(与父菜单项同级)
  376. ...(icon.children && expandedMenus.value.has(icon.name) ?
  377. icon.children.map(child =>
  378. Vue.h('div', {
  379. class: ['menu-item', 'level-2', { active: activeItem.value === child.name }],
  380. onClick: (e) => {
  381. activeItem.value = child.name;
  382. e.stopPropagation();
  383. onMenuClick(child);
  384. }
  385. }, [
  386. Vue.h('div', { class: 'menu-item-content' }, [
  387. Vue.h(SsNavIcon, {
  388. class: child.class || ''
  389. }),
  390. Vue.h('div', { class: 'menu-item-label' }, child.name)
  391. ])
  392. ])
  393. ) : []
  394. )
  395. ]).flat()
  396. ]),
  397. // ===== 固定区域:菜单模式按钮 =====
  398. Vue.h('div', { class: 'fixed-bottom' }, [
  399. Vue.h('div', {
  400. class: 'menu-mode-btn',
  401. onClick: toggleMenuMode
  402. }, [
  403. Vue.h('div', { class: 'mode-label' }, currentMenuMode.value.label)
  404. ])
  405. ])
  406. ])
  407. ]);
  408. }
  409. };
  410. // 基础组件 首页组件头部
  411. export const HeaderContainer = {
  412. name: 'HeaderContainer',
  413. props: {
  414. title: String,
  415. icon: String,
  416. },
  417. emits: ['setting', 'refresh'],
  418. setup(props, { emit }) {
  419. const onSetting = () => {
  420. emit('setting');
  421. };
  422. const onRefresh = () => {
  423. emit('refresh');
  424. };
  425. return {
  426. props,
  427. onSetting,
  428. onRefresh
  429. };
  430. },
  431. render() {
  432. const SsIcon = Vue.resolveComponent('ss-icon');
  433. return Vue.h('div', { class: 'edit-box-header-container' }, [
  434. Vue.h('div', { class: ['title', { visibility: !!(this.props.icon || this.props.title) }] }, [
  435. this.props.icon ? Vue.h('div', { class: 'icon', onClick: this.onRefresh }, [
  436. Vue.h(SsIcon, { class: 'normal', name: this.props.icon, size: '22px' }),
  437. Vue.h(SsIcon, { class: 'hover', name: 'refresh', size: '22px' })
  438. ]) : null,
  439. Vue.h('div', this.props.title)
  440. ]),
  441. Vue.h('div', { class: 'handle-bar' }, [
  442. Vue.h('div', { class: 'left-bar' }), // Assuming left-bar is empty
  443. Vue.h('div', { class: 'setting', onClick: this.onSetting }, [
  444. Vue.h(SsIcon, { name: 'setting', size: '22px' })
  445. ])
  446. ])
  447. ]);
  448. }
  449. };
  450. // 基础组件 首页组件边框
  451. export const EditBox = {
  452. name: 'EditBox',
  453. setup(props, { emit, slots }) {
  454. const mousePos = Vue.reactive({
  455. rightCenter: "right-center",
  456. rightBottom: "right-bottom",
  457. bottomCenter: "bottom-center",
  458. });
  459. const curActionMousePos = Vue.ref("");
  460. const editBoxContainer = Vue.ref(null);
  461. const onMousemove = (e) => {
  462. if (e.buttons === 1 && curActionMousePos.value) {
  463. const dom = editBoxContainer.value;
  464. if (dom) {
  465. const zoom = Number(document.body.style.zoom || 1);
  466. const winRect = dom.getBoundingClientRect();
  467. const { x: xSource, y: ySource } = e;
  468. const x = xSource / zoom;
  469. const y = ySource / zoom;
  470. const val = {
  471. left: winRect.left,
  472. top: winRect.top,
  473. width: winRect.width,
  474. height: winRect.height,
  475. };
  476. const toHObj = (source) => ({
  477. ...source,
  478. height: Math.abs(y - source.top),
  479. top: y >= 0 ? source.top : source.top + (y - source.top),
  480. });
  481. const toWObj = (source) => ({
  482. ...source,
  483. width: Math.abs(x - source.left),
  484. left: x >= 0 ? source.left : source.left + (x - source.left),
  485. });
  486. if (curActionMousePos.value === mousePos.bottomCenter) {
  487. emit("size", toHObj(val));
  488. } else if (curActionMousePos.value === mousePos.rightCenter) {
  489. emit("size", toWObj(val));
  490. } else if (curActionMousePos.value === mousePos.rightBottom) {
  491. emit("size", toWObj(toHObj(val)));
  492. }
  493. }
  494. }
  495. };
  496. const onMouseup = () => {
  497. curActionMousePos.value = "";
  498. };
  499. const onMouseDown = (pos) => {
  500. console.log(pos)
  501. curActionMousePos.value = pos;
  502. };
  503. Vue.onMounted(() => {
  504. document.body.addEventListener("mousemove", onMousemove);
  505. document.body.addEventListener("mouseup", onMouseup);
  506. });
  507. Vue.onUnmounted(() => {
  508. document.body.removeEventListener("mousemove", onMousemove);
  509. document.body.removeEventListener("mouseup", onMouseup);
  510. });
  511. const SsIcon = Vue.resolveComponent('ss-icon');
  512. return () => Vue.h('div', { class: 'edit-box-container', ref: editBoxContainer }, [
  513. Vue.h('div', { class: ['edit-tools', { active: !!curActionMousePos.value }] }, [
  514. Vue.h('div', { class: 'close' }, [
  515. Vue.h(SsIcon, { name: "close-mark-fill", size: "36px" })
  516. ]),
  517. Vue.h('div', { class: 'right-center', onMousedown: () => onMouseDown(mousePos.rightCenter) }, [
  518. Vue.h('div', { class: 'icon' }, [
  519. Vue.h(SsIcon, { name: "resize", size: "30px" })
  520. ])
  521. ]),
  522. Vue.h('div', { class: 'right-bottom', onMousedown: () => onMouseDown(mousePos.rightBottom) }, [
  523. Vue.h('div', { class: 'icon' }, [
  524. Vue.h(SsIcon, { name: "resize", size: "30px" })
  525. ])
  526. ]),
  527. Vue.h('div', { class: 'bottom-center', onMousedown: () => onMouseDown(mousePos.bottomCenter) }, [
  528. Vue.h('div', { class: 'icon' }, [
  529. Vue.h(SsIcon, { name: "resize", size: "30px" })
  530. ])
  531. ])
  532. ]),
  533. Vue.h('div', { class: 'content-area' }, slots.default ? slots.default() : [])
  534. ]);
  535. }
  536. };
  537. // 基础组件 头像
  538. export const Avatar = {
  539. name: 'Avatar',
  540. props: {
  541. url: {
  542. type: String,
  543. required: true
  544. },
  545. size: {
  546. type: [String, Number],
  547. default: 50
  548. },
  549. unit: {
  550. type: String,
  551. default: 'px'
  552. },
  553. shape: {
  554. validator: function (value) {
  555. return ['circle', 'round'].includes(value);
  556. },
  557. default: 'circle'
  558. }
  559. },
  560. setup(props) {
  561. // 计算属性,转换尺寸并添加单位
  562. const style = Vue.computed(() => {
  563. const addUnit = (n) => isNum(n) ? `${n}${props.unit}` : (n || '');
  564. const styleObj = {
  565. width: addUnit(props.size),
  566. height: addUnit(props.size),
  567. };
  568. return toStyleStr(styleObj);
  569. });
  570. // 返回渲染函数所需要的数据
  571. return {
  572. props,
  573. style
  574. };
  575. },
  576. render() {
  577. return Vue.h('img', {
  578. src: this.props.url,
  579. style: this.style.value,
  580. class: ['avatar-container', this.props.shape]
  581. });
  582. }
  583. };
  584. // 基础组件 文件夹或者文件的组件
  585. export const FolderContainer = {
  586. name: 'FolderContainer',
  587. props: {
  588. list: {
  589. type: Array,
  590. required: true,
  591. },
  592. draggable: {
  593. type: Boolean,
  594. default: false,
  595. },
  596. },
  597. setup(props, { emit }) {
  598. const toggleFolder = (index, isFolder) => {
  599. const item = props.list[index];
  600. if (isFolder) {
  601. item.open = !item.open;
  602. }
  603. };
  604. const onClickItem = (item) => {
  605. emit('click', item);
  606. };
  607. const onItemStartDrag = (e, item) => {
  608. e.dataTransfer.setData("text/plain", JSON.stringify(item));
  609. console.log("开始拖拽的对象是=>", { item });
  610. };
  611. const onItemDrop = (e, item, pre) => {
  612. var data = e.dataTransfer.getData("text/plain");
  613. try {
  614. const obj = JSON.parse(data);
  615. item.children.push(obj);
  616. console.log("目标对象=>", { e, item, pre, obj });
  617. } catch (err) {
  618. console.log("拖拽的节点不正确", { item, err });
  619. }
  620. };
  621. return {
  622. toggleFolder,
  623. onClickItem,
  624. onItemStartDrag,
  625. onItemDrop,
  626. };
  627. },
  628. render() {
  629. const SsIcon = Vue.resolveComponent('ss-icon');
  630. return Vue.h('div', { class: 'folder-container' }, this.list.map((groupItem, i) => {
  631. return Vue.h('div', { class: 'group-item', key: i }, [
  632. Vue.h('div', {
  633. class: ['group-title', { active: !!groupItem.curActionMousePos }],
  634. onDrop: $event => this.onItemDrop($event, groupItem),
  635. onDragover: $event => $event.preventDefault(),
  636. }, [
  637. groupItem.type === 'folder' ? Vue.h('div', {
  638. class: 'folder',
  639. onClick: $event => this.toggleFolder(i, groupItem.type === 'folder'),
  640. 'data-num': groupItem.children.length,
  641. }, [
  642. groupItem.open ? Vue.h(SsIcon, { name: 'folder-expand-fill' }) : Vue.h(SsIcon, { name: 'folder-collapse-fill' })
  643. ]) : groupItem.type === 'file' ? Vue.h(SsIcon, { name: 'file' }) : null,
  644. Vue.h('div', groupItem.title)
  645. ]),
  646. groupItem.children.length > 0 && groupItem.open ? Vue.h('ul', {
  647. class: 'group-childs',
  648. onDrop: $event => this.onItemDrop($event, groupItem),
  649. onDragover: $event => $event.preventDefault(),
  650. }, groupItem.children.map((item, j) => {
  651. return Vue.h('li', {
  652. key: j,
  653. draggable: this.draggable,
  654. onDragstart: $event => this.onItemStartDrag($event, item),
  655. onDrop: $event => this.onItemDrop($event, groupItem, item),
  656. onDragover: $event => $event.preventDefault(),
  657. onClick: () => this.onClickItem(item),
  658. }, [
  659. Vue.h('div', item.title),
  660. Vue.h('div', item.time)
  661. ]);
  662. })) : null
  663. ]);
  664. }));
  665. }
  666. };
  667. // 个人卡片
  668. export const UserInfo = {
  669. name: 'UserInfo',
  670. props: {
  671. obj: {
  672. type: Object,
  673. default: () => ({})
  674. }
  675. },
  676. setup(props, { emit }) {
  677. const winInfo = Vue.reactive(loadWinSize(winName.UserInfo));
  678. const onSetting = () => {
  679. console.log("点击了设置按钮");
  680. };
  681. const onRefresh = () => {
  682. console.log("点击了刷新按钮");
  683. };
  684. const onSizeChange = (rect) => {
  685. const style = {};
  686. for (const key in rect) {
  687. style[key] = rect[key] + 'px';
  688. }
  689. saveWinSize(winName.UserInfo, style);
  690. Object.assign(winInfo, style);
  691. };
  692. return {
  693. winInfo,
  694. onSetting,
  695. onRefresh,
  696. onSizeChange,
  697. props
  698. };
  699. },
  700. render() {
  701. const SsIcon = Vue.resolveComponent('ss-icon');
  702. return Vue.h('div', { class: 'user-info-container can-resize-box', style: this.winInfo },
  703. Vue.h(EditBox, {
  704. onSize: this.onSizeChange
  705. }, {
  706. default: () => [
  707. Vue.h('div', { class: 'header' },
  708. Vue.h(HeaderContainer, {
  709. onSetting: this.onSetting,
  710. onRefresh: this.onRefresh
  711. })
  712. ),
  713. Vue.h('div', { class: 'body' }, [
  714. Vue.h('div', { class: 'user-info', style: "margin-bottom: 18px" }, [
  715. Vue.h('div', { class: 'avatar' },
  716. Vue.h(Avatar, {
  717. url: '../images/example/user-avatar.png',
  718. size: '90px'
  719. })
  720. ),
  721. Vue.h('div', { class: 'info' }, [
  722. Vue.h('p', this.props.obj.name + ',上午好!'),
  723. Vue.h('p', '最近登录时间:2024年/08/08 13:03'),
  724. Vue.h('p', '明天有暴雨,记得出门带伞噢!')
  725. ])
  726. ]),
  727. Vue.h('div', { class: 'progress-bar' }, [
  728. Vue.h('div', { class: 'progress' }, [
  729. Vue.h('div', { class: 'line', style: 'width: 60%' }, [
  730. Vue.h('div', '60%(课时)')
  731. ])
  732. ])
  733. ]),
  734. Vue.h('div', { class: 'other-info' }, [
  735. Vue.h('div', {}, [
  736. Vue.h(SsIcon, { name: "userGroup", size: "22px" }),
  737. Vue.h('div', {}, "《关于公司全面预算规划会议》"),
  738. ]),
  739. Vue.h('div', {}, [
  740. Vue.h(SsIcon, { name: "card", type: "common", size: "22px" }),
  741. Vue.h('div', {}, "一卡通余额:**************"),
  742. ]),
  743. Vue.h('div', {}, [
  744. Vue.h(SsIcon, { name: "site", type: "common", size: "22px" }),
  745. Vue.h('div', {}, "个人网站:xxx.xxx.xxx"),
  746. ]),
  747. ])
  748. ])
  749. ]
  750. })
  751. );
  752. }
  753. };
  754. // 待办
  755. export const TodoList = {
  756. name: 'TodoList',
  757. setup() {
  758. const todoGroupList = Vue.reactive([
  759. {
  760. title: "草稿",
  761. type: "folder",
  762. open: false,
  763. children: [
  764. { title: "被退回", time: "08/10 18:12" },
  765. { title: "项目立项申请", time: "08/10 18:12" },
  766. { title: "报销申请", time: "08/10 18:12" },
  767. { title: "资产领用申请", time: "08/10 18:12" },
  768. ],
  769. },
  770. {
  771. title: "被退回",
  772. type: "folder",
  773. open: true,
  774. children: [
  775. { title: "被退回", time: "08/10 18:12" },
  776. { title: "项目立项申请", time: "08/10 18:12" },
  777. { title: "报销申请", time: "08/10 18:12" },
  778. { title: "资产领用申请", time: "08/10 18:12" },
  779. ],
  780. },
  781. {
  782. title: "2020-高薪技术业项目申报",
  783. type: "file",
  784. children: [],
  785. },
  786. ]);
  787. const winInfo = Vue.ref(loadWinSize(winName.TodoList));
  788. const onSetting = () => {
  789. console.log("Clicked on settings button");
  790. };
  791. const onRefresh = () => {
  792. console.log("Clicked on refresh button");
  793. };
  794. const onSizeChange = (rect) => {
  795. console.log(rect)
  796. const style = {};
  797. for (const key in rect) {
  798. style[key] = rect[key] + "px";
  799. }
  800. saveWinSize(winName.TodoList, style);
  801. winInfo.value = style;
  802. };
  803. const onItemClick = (e) => {
  804. console.log("===>>>", e);
  805. };
  806. Vue.onMounted(() => {
  807. // console.log("TodoList component is mounted");
  808. });
  809. return () => Vue.h('div', { class: 'todo-list-container can-resize-box', style: winInfo.value },
  810. Vue.h(EditBox, { onSize: onSizeChange }, {
  811. default: () => [
  812. Vue.h('div', { class: 'header' }, [
  813. Vue.h(HeaderContainer, {
  814. title: "待办",
  815. icon: "todo",
  816. onSetting,
  817. onRefresh
  818. })
  819. ]),
  820. Vue.h('div', { class: 'body' }, [
  821. Vue.h(FolderContainer, { list: todoGroupList, onClick: onItemClick })
  822. ])
  823. ]
  824. })
  825. )
  826. }
  827. };
  828. // 催办
  829. export const UrgingList = {
  830. name: 'UrgingList',
  831. setup() {
  832. const todoGroupList = Vue.reactive([
  833. {
  834. title: "项目",
  835. type: "folder",
  836. open: true,
  837. children: [
  838. { title: "《高新技术企业认定》项目报销", time: "08/10 18:12" },
  839. { title: "日常办公报销", time: "08/10 18:12" },
  840. { title: "固定资产维修费用报销", time: "08/10 18:12" },
  841. ],
  842. },
  843. {
  844. title: "报销",
  845. type: "folder",
  846. open: true,
  847. children: [
  848. {
  849. title: "2020-企业-技术改造专项资金项目-立项申请",
  850. time: "08/10 18:12",
  851. },
  852. ],
  853. },
  854. {
  855. title: "2020-高薪技术企业项目申报",
  856. type: "file",
  857. children: [],
  858. },
  859. {
  860. title: "2020-高薪技术企业项目申报-技术改造专项资金项目-立项申请",
  861. type: "file",
  862. children: [],
  863. },
  864. ]);
  865. const winInfo = Vue.ref(loadWinSize(winName.UrgingList));
  866. const onSetting = () => {
  867. console.log("Clicked on settings button");
  868. };
  869. const onRefresh = () => {
  870. console.log("Clicked on refresh button");
  871. };
  872. const onSizeChange = (rect) => {
  873. const style = {};
  874. for (const key in rect) {
  875. style[key] = rect[key] + "px";
  876. }
  877. saveWinSize(winName.UrgingList, style);
  878. winInfo.value = style;
  879. };
  880. return () =>
  881. Vue.h('div', { class: 'todo-list-container can-resize-box', style: winInfo.value }, Vue.h(EditBox, { onSize: onSizeChange }, {
  882. default: () => [
  883. Vue.h('div', { class: 'header' }, [
  884. Vue.h(HeaderContainer, {
  885. title: "催办",
  886. icon: "alarm-clock",
  887. onSetting,
  888. onRefresh
  889. })
  890. ]),
  891. Vue.h('div', { class: 'body' }, [
  892. Vue.h(FolderContainer, { list: todoGroupList })
  893. ])
  894. ]
  895. })
  896. )
  897. }
  898. };
  899. // 公示公告
  900. export const Notice = {
  901. name: 'Notice',
  902. setup() {
  903. const list = Vue.reactive([
  904. { title: "关于2022年度中层干部的任免公告", time: "10/08 08:30" },
  905. { title: "2022年重组团队从心出发", time: "10/08 08:30" },
  906. { title: "关于单位进入粤港澳创新创业大赛决赛", time: "10/08 08:30" },
  907. { title: "关于2022年度中层干部的任免公告", time: "10/08 08:30" },
  908. ]);
  909. const winInfo = Vue.ref(loadWinSize(winName.Notice));
  910. const onSetting = () => {
  911. console.log("Clicked on settings button");
  912. };
  913. const onRefresh = () => {
  914. console.log("Clicked on refresh button");
  915. };
  916. const onSizeChange = (rect) => {
  917. const style = {};
  918. for (const key in rect) {
  919. style[key] = rect[key] + "px";
  920. }
  921. saveWinSize(winName.Notice, style);
  922. winInfo.value = style;
  923. };
  924. const SsIcon = Vue.resolveComponent('ss-icon');
  925. return () => Vue.h('div', { class: 'notice-list-container can-resize-box', style: winInfo.value }, [
  926. Vue.h(EditBox, { onSize: onSizeChange }, {
  927. default: () => [
  928. Vue.h('div', { class: 'header' }, [
  929. Vue.h(HeaderContainer, {
  930. title: "公示公告",
  931. icon: "notice",
  932. onSetting: onSetting,
  933. onRefresh: onRefresh
  934. })
  935. ]),
  936. Vue.h('div', { class: 'body' }, list.map((item, i) =>
  937. Vue.h('div', { key: i }, [
  938. Vue.h('div', [
  939. Vue.h(SsIcon, { name: "file", size: "22px" }),
  940. Vue.h('span', item.title)
  941. ]),
  942. Vue.h('div', item.time)
  943. ])
  944. ))
  945. ]
  946. })
  947. ]);
  948. }
  949. };
  950. // 快捷发起
  951. export const Launch = {
  952. name: 'Launch',
  953. setup() {
  954. const winInfo = Vue.ref(loadWinSize(winName.launch));
  955. const popupInfo = Vue.reactive({
  956. status: false,
  957. height: 100,
  958. width: 100,
  959. left: 0,
  960. top: 0,
  961. });
  962. const popupStyle = Vue.computed(() => {
  963. const { width, height, left, top } = popupInfo;
  964. return {
  965. left: `${left - (130 - width) / 2}px`,
  966. top: `${top + height}px`,
  967. };
  968. });
  969. const items = Vue.reactive([
  970. { name: "qingjia", text: "请假" },
  971. {
  972. name: "shoufukuan",
  973. text: "收付款",
  974. hasPopup: true,
  975. popupContent: [
  976. { text: "收款" },
  977. { text: "付款" }
  978. ]
  979. },
  980. {
  981. name: "kaoqin",
  982. text: "考勤",
  983. hasPopup: true,
  984. popupContent: [
  985. { text: "2" },
  986. { text: "3" }
  987. ]
  988. }
  989. ]);
  990. const onSetting = () => console.log("Clicked on settings button");
  991. const onRefresh = () => console.log("Clicked on refresh button");
  992. const onMouseMove = (e, item) => {
  993. console.log("鼠标进入了",item.text)
  994. showPopupDialog(e, item)
  995. };
  996. const onMouseleave = (e,item) => {
  997. console.log("鼠标离开了",item.text)
  998. popupInfo.status = false;
  999. };
  1000. const showPopupDialog = (e, item) => {
  1001. const dom = e.target.closest('.item');
  1002. if (dom) {
  1003. const rect = dom.getBoundingClientRect();
  1004. popupInfo.height = rect.height;
  1005. popupInfo.left = rect.left;
  1006. popupInfo.top = rect.top;
  1007. popupInfo.width = rect.width;
  1008. setTimeout(() => {
  1009. popupInfo.status = true;
  1010. }, 600)
  1011. }
  1012. };
  1013. const onSizeChange = (rect) => {
  1014. const style = {};
  1015. for (const key in rect) style[key] = rect[key] + "px";
  1016. saveWinSize(winName.launch, style);
  1017. winInfo.value = style;
  1018. };
  1019. // Vue.onMounted(() => console.log("LaunchContainer component is mounted"));
  1020. const SsIcon = Vue.resolveComponent('ss-icon');
  1021. return () => Vue.h('div', { class: 'launch-container can-resize-box', style: winInfo.value }, [
  1022. Vue.h(EditBox, { onSize: onSizeChange }, {
  1023. default: () => [
  1024. Vue.h('div', { class: 'header' }, [
  1025. Vue.h(HeaderContainer, { title: "快捷发起", icon: "lightning", onSetting, onRefresh })
  1026. ]),
  1027. Vue.h('div', { class: 'body' }, items.map(item =>
  1028. Vue.h('div', { class: 'item', onMousemove: e => onMouseMove(e, item), onMouseleave: e => onMouseleave(e, item) }, [
  1029. Vue.h(SsIcon, {
  1030. class: item.hasPopup && item.popupContent.length > 0 ? "mark-down" : "",
  1031. name: item.name,
  1032. size: "36px"
  1033. }),
  1034. Vue.h('div', { class: 'text' }, item.text),
  1035. item.hasPopup && popupInfo.status ? Vue.h('div', { class: 'popup', style: popupStyle.value }, item.popupContent.map(content =>
  1036. Vue.h('div', content.text)
  1037. )) : null
  1038. ])
  1039. ))
  1040. ]
  1041. })
  1042. ])
  1043. }
  1044. };
  1045. // 项目实时统计图
  1046. export const Statistics = {
  1047. name: 'Statistics',
  1048. setup() {
  1049. const winInfo = Vue.ref(loadWinSize(winName.Statistics));
  1050. const chartInstance = Vue.ref(null);
  1051. const option = {
  1052. tooltip: {
  1053. trigger: "axis",
  1054. axisPointer: {
  1055. type: "cross",
  1056. crossStyle: {
  1057. color: "#999",
  1058. },
  1059. },
  1060. },
  1061. legend: {
  1062. data: ["项目金额", "成本"]
  1063. },
  1064. xAxis: [{
  1065. type: "category",
  1066. data: ["2月", "3月", "4���", "5月", "6月", "7月", "8月", "9月", "10月", "11月"],
  1067. axisPointer: {
  1068. type: "shadow"
  1069. },
  1070. }],
  1071. yAxis: [{
  1072. type: "value",
  1073. name: "单位:万(RMB)",
  1074. min: 0,
  1075. max: 1000,
  1076. interval: 200,
  1077. axisLabel: {
  1078. formatter: "{value} "
  1079. },
  1080. }, {
  1081. type: "value",
  1082. name: "成本",
  1083. min: 0,
  1084. max: 1000,
  1085. interval: 200,
  1086. axisLabel: {
  1087. formatter: "{value}"
  1088. },
  1089. }],
  1090. series: [{
  1091. name: "项目金额",
  1092. type: "bar",
  1093. tooltip: {
  1094. valueFormatter: function (value) {
  1095. return value + " ml";
  1096. }
  1097. },
  1098. data: [250, 850, 500, 650, 450, 850, 780, 450, 700, 850]
  1099. }, {
  1100. name: "成本",
  1101. type: "line",
  1102. yAxisIndex: 1,
  1103. tooltip: {
  1104. valueFormatter: function (value) {
  1105. return value;
  1106. }
  1107. },
  1108. data: [400, 390, 580, 590, 430, 420, 430, 550, 230, 250]
  1109. }]
  1110. }
  1111. // 初始化echants
  1112. const initChart = () => {
  1113. const chartDom = document.getElementById("statistics-chart");
  1114. if (!chartDom) return;
  1115. chartInstance.value = echarts.init(chartDom);
  1116. chartInstance.value.setOption(option);
  1117. };
  1118. const onSetting = () => console.log("Clicked on settings button");
  1119. const onRefresh = () => {
  1120. console.log("Clicked on refresh button");
  1121. if (chartInstance.value) {
  1122. chartInstance.value.clear();
  1123. initChart(); // Reinitialize the chart to reflect any new data or settings
  1124. }
  1125. };
  1126. const onSizeChange = (rect) => {
  1127. const style = {};
  1128. for (const key in rect) style[key] = rect[key] + "px";
  1129. saveWinSize(winName.Statistics, style);
  1130. winInfo.value = style;
  1131. if (chartInstance.value) {
  1132. chartInstance.value.resize();
  1133. }
  1134. };
  1135. Vue.onMounted(() => {
  1136. // console.log("StatisticsContainer component is mounted");
  1137. initChart(); // Initialize the chart when component is mounted
  1138. });
  1139. // return { winInfo, onSetting, onRefresh, onSizeChange };
  1140. return () => Vue.h('div', { class: 'statistics-container can-resize-box', style: winInfo.value }, [
  1141. Vue.h(EditBox, { onSize: onSizeChange }, {
  1142. default: () => [
  1143. Vue.h('div', { class: 'header' }, [
  1144. Vue.h(HeaderContainer, { title: "项目实时统计图", icon: "layer", onSetting, onRefresh })
  1145. ]),
  1146. Vue.h('div', { class: 'body' }, [
  1147. Vue.h('div', { id: 'statistics-chart', class: 'chart-container' })
  1148. ])
  1149. ]
  1150. })
  1151. ]);
  1152. },
  1153. };