commit 1a41ff31f2629bde7d1b3c13dd18aabaf1feb70d Author: shadi Date: Wed Nov 4 16:40:55 2026 +0330 کار اولیه diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..aad064c --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +# System Theme & Configuration +NUXT_PUBLIC_SYSTEM=school + +# Backend API Configuration +NUXT_PUBLIC_BASE_URL=http://localhost:3000/ +NUXT_PUBLIC_API_NAME=api/v1 diff --git a/.env.hamyar b/.env.hamyar new file mode 100644 index 0000000..744d063 --- /dev/null +++ b/.env.hamyar @@ -0,0 +1,4 @@ +# تنظیمات اختصاصی سامانه همیار +NUXT_PUBLIC_SYSTEM=hamyar +NUXT_PUBLIC_BASE_URL=http://192.168.23.102:92/ +NUXT_PUBLIC_API_NAME=api/v1 diff --git a/.env.school b/.env.school new file mode 100644 index 0000000..ef34292 --- /dev/null +++ b/.env.school @@ -0,0 +1,4 @@ +# تنظیمات اختصاصی مدرسه علمیه سفیران هدایت +NUXT_PUBLIC_SYSTEM=school +NUXT_PUBLIC_BASE_URL=http://localhost:3000/ +NUXT_PUBLIC_API_NAME=api/v1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aadb9ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# Nuxt & Nitro build outputs +.nuxt/ +.output/ +dist/ +.nitro/ +.cache/ + +# Dependencies +node_modules/ + +# Logs +logs/ +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +# Environment files +.env +.env*.local +!.env.example +!.env.school +!.env.hamyar + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +!.vscode/settings.json +.idea/ +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Testing & Coverage +coverage/ +*.lcov +.nyc_output/ diff --git a/HELP.md b/HELP.md new file mode 100644 index 0000000..6494991 --- /dev/null +++ b/HELP.md @@ -0,0 +1,2213 @@ +## درباره پروژه + +یک سامانه مدیریت هوشمند مبتنی بر Nuxt 4 است که با هدف [توضیح کوتاه هدف پروژه] توسعه یافته است. + +## تکنولوژی مورد استفاده + +```markdown + "@fullcalendar/core": "^6.1.20", + "@fullcalendar/daygrid": "^6.1.20", + "@fullcalendar/interaction": "^6.1.20", + "@fullcalendar/list": "^6.1.20", + "@fullcalendar/timegrid": "^6.1.20", + "@fullcalendar/vue3": "^6.1.20", + "@iconify-json/meteor-icons": "^1.2.1", + "@nuxt/icon": "^2.2.1", + "@nuxt/ui": "^4.3.0", + "@nuxtjs/i18n": "^10.2.1", + "@pinia/nuxt": "^0.11.3", + "@tiptap/extension-drag-handle": "^3.20.0", + "@tiptap/extension-horizontal-rule": "^3.20.0", + "@tiptap/extension-link": "^3.20.0", + "@tiptap/extension-placeholder": "^3.20.0", + "@tiptap/extension-task-item": "^3.20.0", + "@tiptap/extension-task-list": "^3.20.0", + "@tiptap/extension-text-align": "^3.20.0", + "@tiptap/starter-kit": "^3.20.0", + "@tiptap/vue-3": "^3.20.0", + "@vuelidate/core": "^2.0.3", + "@vuelidate/validators": "^2.0.4", + "@vueuse/integrations": "^14.1.0", + "echarts": "^6.0.0", + "export-from-json": "^1.7.4", + "jalaali-js": "^1.2.8", + "lodash-es": "^4.17.22", + "mammoth": "^1.11.0", + "nuxt": "^4.2.1", + "ohmyfetch": "^0.4.21", + "pinia": "^3.0.4", + "sortablejs": "^1.15.6", + "sweetalert2": "^11.26.4", + "vite-tsconfig-paths": "^6.1.1", + "vue": "^3.5.25", + "vue-router": "^4.6.3", + "vue3-persian-datetime-picker": "^1.2.2" +``` + +## درخت پروژه + +```markdown +pakar/ +├── app +│ ├── apis +│ │ ├── elpApi.js +│ │ └── new-project +│ ├── app.config.ts +│ ├── app.vue +│ ├── assets +│ │ ├── css +│ │ │ ├── main.css +│ │ │ └── tailwindcss +│ │ ├── img +│ │ │ └── captcha.png +│ │ └── pakar +│ │ ├── logo.png +│ │ └── theme.json +│ ├── components +│ │ ├── auto-import +│ │ │ ├── BaseModal.vue +│ │ │ └── LoginForm.vue +│ │ ├── lazy-load +│ │ └── new-project +│ ├── composables +│ │ ├── composSystemTheme.ts +│ │ └── useConfirm.ts +│ ├── json +│ ├── layouts +│ │ └── default.vue +│ ├── manuals +│ │ └── utilities.js +│ ├── middleware +│ ├── pages +│ │ ├── about.vue +│ │ ├── contact.vue +│ │ ├── index.vue +│ │ ├── index.vue.backup +│ │ └── new-project +│ ├── plugins +│ │ ├── httpService.ts +│ │ └── themeLoader.client.ts +│ ├── stores +│ │ ├── authStore.ts +│ │ ├── commonStore.ts +│ │ ├── new-project +│ │ └── permissionStore.ts +│ ├── types +│ └── utils +├── HELP2.md +├── HELP.md +├── nuxt.config.ts +├── package.json +├── package-lock.json +├── public +│ ├── favicon.ico +│ ├── fonts +│ │ ├── sahel +│ │ │ ├── Sahel-Black.eot +│ │ │ ├── Sahel-Black.ttf +│ │ │ ├── Sahel-Black.woff +│ │ │ ├── Sahel-Black.woff2 +│ │ │ ├── Sahel-Bold.eot +│ │ │ ├── Sahel-Bold.ttf +│ │ │ ├── Sahel-Bold.woff +│ │ │ ├── Sahel-Bold.woff2 +│ │ │ ├── Sahel.eot +│ │ │ ├── Sahel-Light.eot +│ │ │ ├── Sahel-Light.ttf +│ │ │ ├── Sahel-Light.woff +│ │ │ ├── Sahel-Light.woff2 +│ │ │ ├── Sahel-SemiBold.eot +│ │ │ ├── Sahel-SemiBold.ttf +│ │ │ ├── Sahel-SemiBold.woff +│ │ │ ├── Sahel-SemiBold.woff2 +│ │ │ ├── Sahel.ttf +│ │ │ ├── Sahel-VF.ttf +│ │ │ ├── Sahel-VF.woff2 +│ │ │ ├── Sahel.woff +│ │ │ └── Sahel.woff2 +│ │ └── vazir +│ │ ├── Vazirmatn-Black.woff2 +│ │ ├── Vazirmatn-Bold.woff2 +│ │ ├── Vazirmatn-ExtraBold.woff2 +│ │ ├── Vazirmatn-ExtraLight.woff2 +│ │ ├── Vazirmatn-Light.woff2 +│ │ ├── Vazirmatn-Medium.woff2 +│ │ ├── Vazirmatn-Regular.woff2 +│ │ ├── Vazirmatn-SemiBold.woff2 +│ │ ├── Vazirmatn-Thin.woff2 +│ │ └── Vazirmatn[wght].woff2 +│ ├── logo +│ │ └── pakar +│ │ ├── dark_logo.png +│ │ └── light_logo.png +│ └── robots.txt +├── README.md +├── tailwind.config.js +└── tsconfig.json +``` + +## کد ها و توضیحات هر بخش + +### 1. theme.json + +```json +{ + "name": "پروژه جدید من", + "title": "عنوان پروژه", + "subTitle": "زیر عنوان پروژه", + "description": "توضیحات پروژه", + "version": "1.0.0", + "logo": { + "light": "/logo/my-project/light_logo.png", + "dark": "/logo/my-project/dark_logo.png", + "favicon": "/favicon.ico", + "icon": "/logo/my-project/icon.png" + }, + "font": "Vazirmatn", + "fontFallback": "system-ui, Tahoma, sans-serif", + "fontFiles": [ + { + "weight": "400", + "style": "normal", + "src": "/fonts/vazir/Vazirmatn-Regular.woff2" + }, + { + "weight": "700", + "style": "normal", + "src": "/fonts/vazir/Vazirmatn-Bold.woff2" + } + ], + "colors": { + "primary": { + "50": "#f0fdf4", + "100": "#dcfce7", + "200": "#bbf7d0", + "300": "#86efac", + "400": "#4ade80", + "500": "#22c55e", + "600": "#16a34a", + "700": "#15803d", + "800": "#166534", + "900": "#14532d", + "950": "#052e16" + } + }, + "layout": { + "containerWidth": "1280px", + "sidebarWidth": "280px", + "headerHeight": "64px", + "footerHeight": "80px" + }, + "darkMode": { + "enabled": true, + "default": "light", + "storageKey": "theme-mode" + }, + "rtl": true, + "direction": "rtl" +} +``` + +### 2. main.css + +```css +/* app/assets/css/main.css */ +@import "tailwindcss"; +@import "@nuxt/ui"; + +@theme static { + /* light-colors */ + --color-light-primary: #fff; + --color-text__orange: #e86c6b; + --color-link-color: #2563eb; + + /* dark-colors */ + --color-dark-primary: #111827; + --color-dark-primary-800: #1f2937; + --color-dark-primary-700: #374151; + --color-dark-primary-600: #4b5563; + --color-dark-primary-500: #6b7280; + --color-dark-primary-400: #9ca3af; + --color-dark-primary-300: #d1d5db; + --color-dark-primary-200: #e5e7eb; + --color-dark-primary-100: #f3f4f6; + --color-dark-primary-50: #f9fafb; + + /* رنگ متن معمولی */ + --color-white-normal: #ffffff; /* متن سفید معمولی */ + --color-black-normal: #111827; /* متن مشکی معمولی */ + + /* متن سفید */ + --color-white-bold: #ffffff; /* متن پررنگ سفید */ + --color-white-light: rgba(255, 255, 255, 0.6); /* متن کم‌رنگ سفید */ + --color-white-strong: #ffffff; /* متن بولد سفید */ + + /* متن خاکستری / دارک */ + --color-dark-normal: #e5e7eb; /* متن خاکستری روشن */ + --color-dark-bold: #111827; /* متن روشن‌تر و بولد */ + --color-dark-light: #6b7280; /* متن کم‌رنگ خاکستری */ + --color-dark-strong: #ffffff; /* متن بولد خاکستری روشن */ + + /* متن غیر فعال */ + --color-text-disabled: #9ca3af; + + /* رنگ های دلخواه دیگر */ + --color-text-orange: #e86c6b; + --color-link-color: #2563eb; +} + +/* تعریف رنگ دلخواه */ +/* primary-colors */ +/* --color-primary: #00b6e3; */ +/* --color-primary-50: #e0f6fb; +--color-primary-100: #b3e9f7; +--color-primary-200: #80d8f3; +--color-primary-300: #4dc6ef; +--color-primary-400: #1ab4eb; +--color-primary-500: #00b6e3; +--color-primary-600: #0097b0; +--color-primary-700: #007580; +--color-primary-800: #005250; +--color-primary-900: #002f30; +--color-primary-950: #001519; */ + +* { + font-family: var(--app-font), sans-serif !important; +} + +html, +body, +#__nuxt, +.root { + font-family: var(--app-font), sans-serif !important; + direction: rtl; + text-align: right; +} +button, +a { + cursor: pointer; +} +``` + +### 3. BaseModal.vue + +```javascript + + + + + +``` + +### 4. composSystemTheme.ts + +```typescript +import { ref, computed } from "vue"; +import { useState } from "#imports"; + +export function composSystemTheme() { + const isDark = useState("is-dark", () => false); + const { $theme, $themeKey } = useNuxtApp(); + const currentTheme = useState("theme", () => $theme) + const themeKey = ref($themeKey); + + const toggleDarkMode = () => { + isDark.value = !isDark.value; + if (process.client) { + localStorage.setItem("theme-mode", isDark.value ? "dark" : "light"); + const root = document.documentElement; + isDark.value ? root.classList.add("dark") : root.classList.remove("dark"); + } + }; + + const logo = computed(() => { + if (!currentTheme.value) return ""; + return isDark.value + ? currentTheme.value.logo.dark + : currentTheme.value.logo.light; + }); + + const primaryColor = computed(() => { + if (process.client) { + const v = getComputedStyle(document.documentElement) + .getPropertyValue("--color-primary-500") + .trim(); + if (v) return v; + } + return currentTheme.value?.colors?.primary?.["500"] || "#4caf50"; + }); + + const applyTheme = async () => { + return currentTheme.value; + }; + + return { + applyTheme, + currentTheme, + isDark, + toggleDarkMode, + logo, + primaryColor, + themeKey, + }; +} +``` + +### 5. useConfirm.ts + +```typescript +// ~/composables/confirm.ts +import { reactive, readonly } from "vue"; + +// یک state مشترک برای تمام کامپوننت‌ها +const confirmState = reactive({ + isOpen: false, + title: "تأیید عملیات", + message: "آیا از انجام این عملیات اطمینان دارید؟", + resolve: null as ((value: boolean) => void) | null, +}); + +export const useConfirmState = () => readonly(confirmState); + +export const useConfirm = () => { + const ucoShowConfirmModal = ( + options: { title?: string; message?: string } = {} + ): Promise => { + confirmState.title = options.title || "تأیید عملیات"; + confirmState.message = + options.message || "آیا از انجام این عملیات اطمینان دارید؟"; + confirmState.isOpen = true; + + return new Promise((resolve) => { + confirmState.resolve = resolve; + }); + }; + + return { ucoShowConfirmModal }; +}; + +export const useConfirmActions = () => { + const ucoConfirm = () => { + confirmState.isOpen = false; + if (confirmState.resolve) confirmState.resolve(true); + confirmState.resolve = null; + }; + + const ucoCancelConfirmModal = () => { + confirmState.isOpen = false; + if (confirmState.resolve) confirmState.resolve(false); + confirmState.resolve = null; + }; + + return { ucoConfirm, ucoCancelConfirmModal }; +}; + +``` + +### 6. layouts/default.vue + +```javascript + + + + + +``` + +### 7. manuals/utilities.js + +```javascript + +// import Vue from "vue"; +// const crypto = require("crypto"); +import exportFromJSON from "export-from-json"; +// import store from "@store/store"; +export const isLoginRemoved = () => process.env.VUE_APP_LOGIN_REMOVE == 1; + +// util to export to excel file using plugin +// https://github.com/zheeeng/export-from-json +export const convertJsonToExcelUsingPlugin = async ( + data, + fileName = "download" +) => { + // 'txt'(default), 'css', 'html', 'json', 'csv', 'xls', 'xml' + const exportType = exportFromJSON.types.xls; + const withBOM = true; + + return await exportFromJSON({ data, fileName, exportType, withBOM }); +}; + +// util to export to excel file manually +export const exportJsonToExcelManually = (JSONData, FileTitle, ShowLabel) => { + //If JSONData is not an object then JSON.parse will parse the JSON string in an Object + var arrData = typeof JSONData != "object" ? JSON.parse(JSONData) : JSONData; + var CSV = ""; + //This condition will generate the Label/Header + if (ShowLabel) { + var row = ""; + //This loop will extract the label from 1st index of on array + for (var index in arrData[0]) { + //Now convert each value to string and comma-seprated + row += encodeURI(index) + ","; + } + row = row.slice(0, -1); + //append Label row with line break + CSV += row + "\r\n"; + } + //1st loop is to extract each row + for (var i = 0; i < arrData.length; i++) { + var row = ""; + //2nd loop will extract each column and convert it in string comma-seprated + for (var index in arrData[i]) { + row += '"' + arrData[i][index] + '",'; + } + row.slice(0, row.length - 1); + //add a line break after each row + CSV += row + "\r\n"; + } + if (CSV == "") { + alert("Invalid data"); + return; + } + //Generate a file name + // application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8; + // text/csv;charset=utf-8; + // var csvContent = "data:text/csv;charset=utf-8,%EF%BB%BF" + encodeURI(csvContent); + + var filename = FileTitle; + var blob = new Blob([CSV], { + type: "text/csv;charset=utf-8,BOM", + }); + + if (navigator.msSaveBlob) { + // IE 10+ + navigator.msSaveBlob(blob, filename); + } else { + var link = document.createElement("a"); + if (link.download !== undefined) { + // feature detection + // Browsers that support HTML5 download attribute + var url = URL.createObjectURL(blob); + link.setAttribute("href", url); + link.style = "visibility:hidden"; + link.download = filename + ".csv"; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + } +}; + +// util to delay promise +export const wait = (ms) => { + return (x) => { + return new Promise((resolve) => setTimeout(() => resolve(x), ms)); + }; +}; +// util to createObjectByNewProperties +export const createObjectByNewProperties = (list, allowedProperties) => { + const properties = []; + + list.forEach((item, index) => { + const filtered = Object.keys(item) + .filter((key) => allowedProperties.includes(key)) + .reduce((obj, key) => { + obj[key] = item[key]; + return obj; + }, {}); + + properties[index] = filtered; + }); + return properties; +}; +// util to convert digits to character +export const toNumbersInCharacters = (number) => { + const persianNumbers = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "۰"]; + const arabicNumbers = ["١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩", "٠"]; + const englishNumbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]; + const persianNumbersInCharacters = [ + "یک", + "دو", + "سه", + "چهار", + "پنج", + "شش", + "هفت", + "هشت", + "نه", + "صفر", + ]; + + // only replace english number with persian number character + return persianNumbersInCharacters[englishNumbers.indexOf(number)]; + + // convert all numbers to persian digits + // return str.split("").map(c => + // persianNumbersInCharacters[englishNumbers.indexOf(c)] || + // persianNumbersInCharacters[englishNumbers.indexOf(c)] || c).join("") +}; +// util to handle if img src is not valid +export const handleImageSrcOnError = ({ target }, isUserAvatar = true) => { + if (isUserAvatar) target.classList.add("human-avatar"); + target.classList.add("error"); +}; +// util to convert date to local date and time strng; +export const persianDateAndTime = (stringDate, local = "fa-IR") => { + let date = new Date(stringDate); + let jsonDate = { + weekday: { + long: date.toLocaleDateString(local, { weekday: "long" }), + short: date.toLocaleDateString(local, { weekday: "short" }), + narrow: date.toLocaleDateString(local, { weekday: "narrow" }), + }, + era: { + long: date.toLocaleDateString(local, { era: "long" }), + short: date.toLocaleDateString(local, { era: "short" }), + narrow: date.toLocaleDateString(local, { era: "narrow" }), + }, + timeZoneName: { + long: date.toLocaleDateString(local, { timeZoneName: "long" }), + short: date.toLocaleDateString(local, { timeZoneName: "short" }), + }, + year: { + numeric: date.toLocaleDateString(local, { year: "numeric" }), + "2-digit": date.toLocaleDateString(local, { year: "2-digit" }), + }, + month: { + numeric: date.toLocaleDateString(local, { month: "numeric" }), + "2-digit": date.toLocaleDateString(local, { month: "2-digit" }), + long: date.toLocaleDateString(local, { month: "long" }), + short: date.toLocaleDateString(local, { month: "short" }), + narrow: date.toLocaleDateString(local, { month: "narrow" }), + }, + day: { + numeric: date.toLocaleDateString(local, { day: "numeric" }), + "2-digit": date.toLocaleDateString(local, { day: "2-digit" }), + }, + hour: { + numeric: date.toLocaleTimeString(local, { hour: "numeric" }), + "2-digit": date.toLocaleTimeString(local, { hour: "2-digit" }), + }, + minute: { + numeric: date.toLocaleTimeString(local, { minute: "numeric" }), + "2-digit": date.toLocaleTimeString(local, { minute: "2-digit" }), + }, + second: { + numeric: date.toLocaleTimeString(local, { second: "numeric" }), + "2-digit": date.toLocaleTimeString(local, { second: "2-digit" }), + }, + }; + return jsonDate; +}; +// util to format numbers to local curency +export const formatNumber = (price = "") => { + return new Intl.NumberFormat("fa-IR").format(price); +}; + +export const isValidHttpUrl = (string) => { + let url; + + try { + url = new URL(string); + } catch (_) { + return false; + } + + return url.protocol === "http:" || url.protocol === "https:"; +}; +export const addJsCssFileToDom = (fileUrl, fileType, uuid) => { + let targetElement = + fileType == "js" ? "script" : fileType == "css" ? "link" : "none"; + let targetAttr = + fileType == "js" ? "src" : fileType == "css" ? "href" : "none"; + + let node = document.createElement(targetElement); + node.setAttribute(targetAttr, fileUrl); + node.setAttribute("id", targetElement + "-" + uuid); + + document.head.appendChild(node); +}; +export const removeJsCssFileFromDom = (fileType, uuid) => { + let targetElement = + fileType == "js" ? "script" : fileType == "css" ? "link" : "none"; + document.getElementById(targetElement + "-" + uuid)?.remove(); +}; +export const clearBodyClass = (className = undefined) => { + if (className) document.querySelector("html").replace(className, ""); + else document.querySelector("html").removeAttribute("class"); +}; +export const redirectToExternalLink = (href, openInNewTab) => { + if (href) { + if (isValidHttpUrl(href) && openInNewTab) window.open(href, "_blank"); + else if (isValidHttpUrl(href) && !openInNewTab) window.location.href = href; + else if (!isValidHttpUrl(href) && openInNewTab) { + if (href.includes("www.")) window.open("http://" + href, "_blank"); + } else if (!isValidHttpUrl(href) && !openInNewTab) { + if (href.includes("www.")) window.location.href = "http://" + href; + } + } +}; +export const extractAllQueryParams = (href) => { + return new URLSearchParams(href); + + // return new Proxy(new URLSearchParams(href), { + // get: (searchParams, prop) => searchParams.get(prop), + // }); +}; +export const makeQueryParams = (url, searchParams) => { + var query = new URLSearchParams(); + + // (A) URL SEARCH PARAMS OBJECT TO QUICKLY BUILD QUERY STRING + Object.keys(searchParams).forEach((key) => + query.append(key, searchParams[key]) + ); + + // (B) CONVERT TO STRING, APPEND TO URL + url += "?" + query.toString(); + return url; +}; + +// export const decryptData = ( +// data, +// key = "fTjWnZr4u7x!A%D*G-KaNdRgUkXp3s6v", +// method = "AES-256-CBC", +// iv = "poaskq2234??@35." +// ) => { +// let decipher = crypto.createDecipheriv(method, key, iv); +// let decrypted = decipher.update(data, "base64", "utf8"); +// let dd = decrypted + decipher.final("utf8"); +// return JSON.parse(dd); +// }; + +// util to handle response errors + +export const handleErrors = (error) => { + return new Promise((resolve, reject) => { + /* + 401: The HTTP 401 Unauthorized response status code indicates that + the client request has not been completed because it lacks + valid authentication credentials for the requested resource. + + 403: The HTTP 403 Forbidden response status code indicates that + the server understands the request but refuses to authorize it. + + 404: The HTTP 404 Not Found response status code indicates that + the server cannot find the requested resource + + 405: The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed + response status code indicates that the server knows the + request method, but the target resource doesn't support this method + + 406: Not Acceptable + */ + try { + let res = error.response; + + if (res) { + if (res.status === 401) { + toast.add({ + title: "خطا!", + description: res.data.message, + }); + + // router.push({ name: 'login' }) + } else if (res.status === 403) { + toast.add({ + title: "خطا!", + description: res.data.message, + }); + } else if (res.status === 404) { + toast.add({ + title: "خطا!", + description: res.data.message, + }); + + // router.push('/404') + } else if (res.status === 405) { + toast.add({ + title: "خطا!", + description: res.data.message, + }); + + // router.push('/404') + } else if (res.status === 406) { + toast.add({ + title: "خطا!", + description: res.data.message, + }); + + // router.push('/404') + } else if (res.status === 500) { + toast.add({ + title: "خطا!", + description: res.data.message ?? res.data, + }); + } else { + toast.add({ + title: "خطا!", + description: res.data.message, + }); + } + + resolve(error.response); + } else { + let message = "خطا!!!"; + + // if (error) { + // message = error.message ?? error; + // } + // else + // { + // message = "خطا!!!" + // } + + reject(new Error(message)); + + // text: error.stack, + toast.add({ + title: message, + }); + } + } catch (error) { + let message = "خطا!!!"; + message = error?.message ?? message; + + return reject(new Error(message)); + } + }); +}; + +function countDownTimer(timeInSecond = 120) { + var timeleft = timeInSecond; + var downloadTimer = setInterval(function () { + if (timeleft <= 0) { + clearInterval(downloadTimer); + // document.getElementById("countdown").innerHTML = "Finished"; + } else { + // document.getElementById("countdown").innerHTML = + // timeleft + " seconds remaining"; + } + timeleft -= 1; + }, 1000); + + return timeleft; +} + +/////////////////////////////////////// +///// html functions +/////////////////////////////////////// +export function getSelectionHtmlRange() { + var sel; + if (window.getSelection) { + sel = window.getSelection(); + if (sel.rangeCount) { + return sel.getRangeAt(0); + } + } else if (document.selection) { + return document.selection.createRange(); + } + return null; +} + +export function getSelectedHtmlInfo() { + const selectRange = getSelectionHtmlRange(); + if (!selectRange) return {}; + + // if (selectRange.startContainer !== selectRange.endContainer) { + // return; + // } + + let begin = 0; + let strBegin = ""; + let prevFullText = ""; + if (selectRange.startOffset > 0) + strBegin = selectRange.startContainer.textContent.substring( + 0, + selectRange.startOffset - 1 + ); + + // برای وقتی که در تگ قبلی ، شماره کلمه انتها ذخیره شده است و نیازی به بررسی قبل از آن نیست + if ( + selectRange.commonAncestorContainer.previousSibling && + selectRange.commonAncestorContainer.previousSibling.dataset?.end + ) { + begin = + parseInt( + selectRange.commonAncestorContainer.previousSibling.dataset.end + ) + 1; + begin += splitWord(strBegin).length; + } else { + prevFullText = getPreviousHtmlText(selectRange.startContainer, selectRange); + begin += splitWord(prevFullText).length; + } + + let selectedText = selectRange.startContainer.textContent.substring( + selectRange.startOffset, + selectRange.endOffset + ); + let end = begin + splitWord(selectedText).length - 1; + + /////////////////////////////////////////////////////// + ///// استخراج کلمه کلیک شده و دو کلمه بعدش + ///// برای حالتی که متنی انتخاب نشده و فقط کلیک شده نیاز هست + + let node = selectRange.startContainer; + const fullText = node.textContent; + const offset = selectRange.startOffset; + + const words = fullText.split(/\s+/); + let totalChars = 0; + let wordIndex = -1; + let wordsClicked = ""; + + /// چون احتمال داره وسط کلمه کلیک شده باشه، قبل کلمه کلیک شده می ایستیم + for (let i = 0; i < words.length; i++) { + totalChars += words[i].length + 1; + if (offset < totalChars) { + wordIndex = i; + break; + } + } + + if (wordIndex !== -1) { + wordsClicked = + words[wordIndex] + + " " + + (words[wordIndex + 1] || "") + + " " + + (words[wordIndex + 2] || ""); + } + /////////////////////////////////////////////////////// + + let info = { + begin: begin, + end: end, + selectedText: selectedText, + prevTextBegin: strBegin, + texts: wordsClicked, + // prevTextFull: prevFullText, + }; + return info; +} + +export function getPreviousHtmlText(node, selectRange = null) { + let text = ""; + if (!node) return text; + else if (selectRange && node == selectRange.startContainer) { + if (selectRange.startOffset > 0) + text = selectRange.startContainer.textContent.substring( + 0, + selectRange.startOffset - 1 + ); + // else + // text = selectRange.startContainer.textContent; + } else text = node.textContent; + + if (node.previousSibling) + text = getPreviousHtmlText(node.previousSibling, null) + text; + + return text; +} +//////////////////////////////////////////////////////////////////// + +export function splitWord(text) { + let items = text.split( + /[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>\/,;،؛ \-!?:٭؟]+/ + ); + // let items = text.split("\t\n\r.'\"«»)(][{}%#$*<>/,;،؛ -!?:٭؟") + return items; +} + +export function normalizeText( + text, + options = { charArNormal: true, errorLine: true } +) { + // //defualt + // options = { + // charArNormal: true, + // errorLine: true, + // alphabetsNormal: false, + // emptylinesNormal: false, + // hamzehNormal: false, + // spaceCorrection: false, + // trimLine: false + // }; + + text = text.trim(); + + //اصلاح خطاهای متن در کد خط + if (options?.errorLine) { + text = text.replaceAll("\\n", "\n"); + text = text.replaceAll("\\r", "\r"); + text = replaceRegText("(\r\n)+", "\n", text); + text = text.replaceAll("\r", "\n"); + + //شنبهها ==> شنبه‌ها + //رسیدگیهای ==> رسیدگی‌های + // text = replaceRegText("(ه)(ها)", /\1\2/gm, text); + } + // یکسان سازی اختلاف حروف کیبوردهای مختلف - کدهای مختلف ولی نمایش یکسان + if (options?.alphabetsNormal) { + text = replaceAlphabets(text); + } + + //حذف خطوط و فاصله‌های خالی + if (options?.emptylinesNormal) { + text = replaceRegText("( )+", " ", text); + text = replaceRegText("(\n)+", "\n", text); + } + + // نرمال کردن حروف اختلافی عربی و فارسی + if (options?.charArNormal) { + text = text.replaceAll("ي", "ی"); + text = text.replaceAll("ك", "ک"); + } + + // پرش از اختلافات همزه‌ای + if (options?.hamzehNormal) { + text = replaceRegText("ئ|ﺋ", "ی", text); + text = replaceRegText("ؤ|ﺅ", "و", text); + text = replaceRegText("ﺔ|ۀ|ة", "ه", text); + text = replaceRegText("إ|أ", "ا", text); + } + if (options?.dateNormal) { + text = dateNormalize(text); + } + if (options?.spaceCorrection) { + text = spaceCorrection(text); + } + + // حذف خطوط اضافی اول و انتهای متن + if (options?.trimLine) text = text.replace(/^\s+|\s+$/g, ""); + + text = text.trim(); + + return text; +} + +//برعکس بودن تاریخ ها را درست میکند +export function dateNormalize(text, forWord = false) { + if (forWord) { + // فرمت YYYY/MM/DD یا YYYY-MM-DD + text = replaceRegText( + /(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})/, + (_, year, month, day) => + `${day.padStart(2, "0")}/${month.padStart(2, "0")}/${year}`, + text + ); + + // // فرمت DD/MM/YYYY یا DD-MM-YYYY + // text = replaceRegText( + // /(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, + // (_, day, month, year) => + // `${year}/${month.padStart(2, "0")}/${day.padStart(2, "0")}`, + // text + // ); + } else { + // فرمت YYYY/MM/DD یا YYYY-MM-DD + text = replaceRegText( + /(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})/, + (_, year, month, day) => + `${year}/${month.padStart(2, "0")}/${day.padStart(2, "0")}`, + text + ); + + // فرمت DD/MM/YYYY یا DD-MM-YYYY + text = replaceRegText( + /(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, + (_, day, month, year) => + `${year}/${month.padStart(2, "0")}/${day.padStart(2, "0")}`, + text + ); + } + + // // فرمت MM/DD/YYYY + // text = replaceRegText( + // /(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, + // (_, month, day, year) => + // `${year}/${month.padStart(2, "0")}/${day.padStart(2, "0")}`, + // text + // ); + return text; +} + +export function replaceAlphabets(text) { + let res = text; + res = res.replaceAll("\u00AD", "\u200C"); + res = res.replaceAll("\u00AC", "\u200C"); // نیم اسپیس خاص + + res = replaceRegText("ﺁ|آ", "آ", res); + res = replaceRegText("ﺎ|ٱ|ﺍ", "ا", res); // + res = replaceRegText("ٲ|أ|ﺄ|ﺃ", "أ", res); + res = replaceRegText("ﺈ|ﺇ", "إ", res); + res = replaceRegText("ﺐ|ﺏ|ﺑ|ﺒ", "ب", res); + res = replaceRegText("ﭖ|ﭗ|ﭙ|ﭘ", "پ", res); + res = replaceRegText("ﭡ|ٺ|ٹ|ﭞ|ٿ|ټ|ﺕ|ﺗ|ﺖ|ﺘ", "ت", res); + res = replaceRegText("ﺙ|ﺛ|ﺚ|ﺜ", "ث", res); + res = replaceRegText("ﺝ|ڃ|ﺠ|ﺟ", "ج", res); + res = replaceRegText("ڃ|ﭽ|ﭼ", "چ", res); + res = replaceRegText("ﺢ|ﺤ|څ|ځ|ﺣ", "ح", res); + res = replaceRegText("ﺥ|ﺦ|ﺨ|ﺧ", "خ", res); + res = replaceRegText("ڏ|ډ|ﺪ|ﺩ", "د", res); + res = replaceRegText("ﺫ|ﺬ|ذ", "ذ", res); + res = replaceRegText("ڙ|ڗ|ڒ|ڑ|ڕ|ﺭ|ﺮ", "ر", res); + res = replaceRegText("ﺰ|ﺯ", "ز", res); + res = replaceRegText("ﮊ", "ژ", res); + res = replaceRegText("ݭ|ݜ|ﺱ|ﺲ|ښ|ﺴ|ﺳ", "س", res); + res = replaceRegText("ﺵ|ﺶ|ﺸ|ﺷ", "ش", res); + res = replaceRegText("ﺺ|ﺼ|ﺻ|ﺹ", "ص", res); // + res = replaceRegText("ﺽ|ﺾ|ﺿ|ﻀ", "ض", res); + res = replaceRegText("ﻁ|ﻂ|ﻃ|ﻄ", "ط", res); + res = replaceRegText("ﻆ|ﻇ|ﻈ", "ظ", res); + res = replaceRegText("ڠ|ﻉ|ﻊ|ﻋ|ﻌ", "ع", res); + res = replaceRegText("ﻎ|ۼ|ﻍ|ﻐ|ﻏ", "غ", res); + res = replaceRegText("ﻒ|ﻑ|ﻔ|ﻓ", "ف", res); + res = replaceRegText("ﻕ|ڤ|ﻖ|ﻗ|ﻘ", "ق", res); + res = replaceRegText("ڭ|ﻚ|ﮎ|ﻜ|ﮏ|ګ|ﻛ|ﮑ|ﮐ|ڪ|ك", "ک", res); + res = replaceRegText("ﮚ|ﮒ|ﮓ|ﮕ|ﮔ", "گ", res); + res = replaceRegText("ﻝ|ﻞ|ﻠ|ڵ|ﻟ", "ل", res); // + res = replaceRegText("ﻵ|ﻶ|ﻷ|ﻸ|ﻹ|ﻺ|ﻻ|ﻼ", "لا", res); // + res = replaceRegText("ﻡ|ﻤ|ﻢ|ﻣ", "م", res); + res = replaceRegText("ڼ|ﻦ|ﻥ|ﻨ|ﻧ", "ن", res); + res = replaceRegText("ވ|ﯙ|ۈ|ۋ|ﺆ|ۊ|ۇ|ۏ|ۅ|ۉ|ﻭ|ﻮ|ؤ", "و", res); + res = replaceRegText("ﻬ|ھ|ﻩ|ﻫ|ﻪ|ە|ہ", "ه", res); + res = replaceRegText("ﭛ|ﻯ|ۍ|ﻰ|ﻱ|ﻲ|ں|ﻳ|ﻴ|ﯼ|ې|ﯽ|ﯾ|ﯿ|ێ|ے|ى|ي", "ی", res); + res = replaceRegText("¬", "‌", res); + res = replaceRegText("•|·|●|·|・|∙|。|ⴰ", ".", res); + res = replaceRegText(",|٬|٫|‚|،", "،", res); + res = replaceRegText("ʕ", "؟", res); + res = replaceRegText("۰|٠", "0", res); + res = replaceRegText("۱|١", "1", res); + res = replaceRegText("۲|٢", "2", res); + res = replaceRegText("۳|٣", "3", res); + res = replaceRegText("۴|٤", "4", res); + res = replaceRegText("۵", "5", res); + res = replaceRegText("۶|٦", "6", res); + res = replaceRegText("۷|٧", "7", res); + res = replaceRegText("۸|٨", "8", res); + res = replaceRegText("۹|٩", "9", res); + res = replaceRegText("²", "2", res); + res = replaceRegText("|ِ|ُ|َ|ٍ|ٌ|ً|", "", res); + // res = replaceRegText("ـ", "_", res); + res = replaceRegText("ـ", "-", res); // + + // res = replaceRegText("([\u0600-\u06FF])ـ([\u0600-\u06FF])", "\1\2", res) // حذف حروف کشیده + // res = replaceRegText("([\u0600-\u06FF])ـ", "\1", res) // حذف حروف کشیده + + res = res.replace(/\u200C+$/, ""); + res = res.trim(); + + return res; +} + +export function spaceCorrection(text) { + let res = text; + res = replaceRegText("^(بی|می|نمی)( )", "$1‌", res); + res = replaceRegText("( )(می|نمی|بی)( )", "$1$2‌", res); + res = replaceRegText( + "( )(هایی|ها|های|ایی|هایم|هایت|هایش|هایمان|هایتان|هایشان|ات|ان|ین|انی|بان|ام|ای|یم|ید|اید|اند|بودم|بودی|بود|بودیم|بودید|بودند|ست)( )", + "‌$2$3", + res + ); + res = replaceRegText("( )(شده|نشده)( )", "‌$2‌", res); + res = replaceRegText( + "( )(طلبان|طلب|گرایی|گرایان|شناس|شناسی|گذاری|گذار|گذاران|شناسان|گیری|پذیری|بندی|آوری|سازی|بندی|کننده|کنندگان|گیری|پرداز|پردازی|پردازان|آمیز|سنجی|ریزی|داری|دهنده|آمیز|پذیری|پذیر|پذیران|گر|ریز|ریزی|رسانی|یاب|یابی|گانه|گانه‌ای|انگاری|گا|بند|رسانی|دهندگان|دار)( )", + "‌$2$3", + res + ); + return res; +} + +export function replaceRegText(pattern, replacement, text) { + const regex = new RegExp(pattern, "g"); + return text.replace(regex, replacement); +} + +export function generateUID() { + // I generate the UID from two parts here + // to ensure the random number provide enough bits. + var firstPart = (Math.random() * 46656) | 0; + var secondPart = (Math.random() * 46656) | 0; + firstPart = ("000" + firstPart.toString(36)).slice(-3); + secondPart = ("000" + secondPart.toString(36)).slice(-3); + return firstPart + secondPart; // eg : 9c8yxr +} + +function myEncodeQuery(text) { + if (!text || text == "") return ""; + //text = JSON.stringify(text); + let ch1 = encodeURIComponent("#"); + let ch3 = encodeURIComponent("\\"); + let ch4 = encodeURIComponent("&"); + text = text.replaceAll("#", ch1); + text = text.replaceAll("&", ch4); + text = text.replaceAll("/", "\\"); + text = text.replaceAll("\\", ch3); + + // با تبدیل نقطه مشکل نشانی درخواست در بک حل نشد + //text = text.replaceAll(".", '%2E'); + return text; +} + +export function cleanTextUnpermittedChars(text) { + if (!text) return ""; + + text = text.replaceAll("([0x0000-0x001F]|(0x007F))", ""); + return text; +} + + +// utils/tree.js +export function findNodeWithPath(nodes, targetId, path = []) { + for (let i = 0; i < nodes.length; i++) { + const node = nodes[i]; + const currentPath = [...path, i]; + + // ✅ Adjust this condition based on how you identify a node + if (node.id === targetId) { + return { node, path: currentPath }; + } + + // Recurse into children if they exist + if (node.children && node.children.length > 0) { + const result = findNodeWithPath(node.children, targetId, currentPath); + if (result) return result; + } + } + return null; // Not found +} + +export function updateNodeByPath(nodes, path, newValue) { + let current = nodes; + // Navigate to the parent of the target node + for (let i = 0; i < path.length - 1; i++) { + current = current[path[i]].children; + } + // Update the target node + const targetIndex = path[path.length - 1]; + current[targetIndex] = { ...current[targetIndex], ...newValue }; +} + +////////////////////////////////////////// + +// export { wait, handleErrors } + +``` + +### 8. plugins/httpService.ts + +```typescript + +import { useStorage } from "@vueuse/core"; + +export default defineNuxtPlugin((nuxtApp) => { + // ====================== + // Runtime Config (Public) + // ====================== + const config = useRuntimeConfig(); + + const BASE_URL = config.public.NUXT_PUBLIC_BASE_URL || ""; + const API_NAME = config.public.NUXT_PUBLIC_API_NAME || ""; + + // ====================== + // Safe URL Joiner + // ====================== + const joinURL = (base: string, path: string) => { + return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`; + }; + + const baseURL = joinURL(BASE_URL, API_NAME); + + // ====================== + // Reactive Token + // ====================== + const token = useStorage("id_token", "GuestAccess"); + + // ====================== + // Fetch Instance + // ====================== + const api = $fetch.create({ + baseURL, + + // ====================== + // Request Interceptor + // ====================== + onRequest({ options }) { + const auth = token.value; + if (!auth) return; + const headers = (options.headers ||= {}); + if (headers instanceof Headers) { + headers.set("Authorization", auth); + } else if (Array.isArray(headers)) { + headers.push(["Authorization", auth]); + } else { + headers.Authorization = auth; + } + }, + + // ====================== + // Response Handler + // ====================== + onResponse({ response }) { + return response._data; + }, + + // ====================== + // Error Handler + // ====================== + async onResponseError({ response }) { + const status = response?.status; + + if (status === 401) { + token.value = null; + await nuxtApp.runWithContext(() => navigateTo("/login")); + } + + throw { + status, + message: + response?._data?.message || response?.statusText || "خطای نامشخص", + data: response?._data || null, + }; + }, + }); + + // ====================== + // HTTP Service (Public API) + // ====================== + const http = { + getRequest: (url: string, options: any = {}) => + api(url, { method: "GET", ...options }), + + postRequest: (url: string, body: any, options: any = {}) => + api(url, { method: "POST", body, ...options }), + + putRequest: (url: string, body: any, options: any = {}) => + api(url, { method: "PUT", body, ...options }), + + patchRequest: (url: string, body: any, options: any = {}) => + api(url, { method: "PATCH", body, ...options }), + + deleteRequest: (url: string, options: any = {}) => + api(url, { method: "DELETE", ...options }), + }; + + // ====================== + // Provide to Nuxt + // ====================== + return { + provide: { + http, + }, + }; +}); + + +``` + +### 9. plugins/themeLoader.client.ts + +```typescript +// plugins/00-themeLoader.client.ts +import pakar from "~/assets/pakar/theme.json"; + +export const themes = { pakar }; + +type ThemeKey = keyof typeof themes; +type ThemeConfig = (typeof themes)[ThemeKey]; + +function hexToRgb(hex: string): string { + hex = hex.replace("#", ""); + if (hex.length === 3) + hex = hex + .split("") + .map((c) => c + c) + .join(""); + const r = parseInt(hex.substring(0, 2), 16); + const g = parseInt(hex.substring(2, 4), 16); + const b = parseInt(hex.substring(4, 6), 16); + return `${r} ${g} ${b}`; +} + +export default defineNuxtPlugin(() => { + if (!process.client) return; + + const html = document.documentElement; + + // انتخاب تم - فقط پاکار + const key: ThemeKey = "pakar"; + const theme: ThemeConfig = themes[key]; + + // ست کردن CSS variables + if (theme.colors && (theme as any).colors.primary) { + Object.entries((theme as any).colors.primary).forEach(([shade, val]) => { + html.style.setProperty(`--color-primary-${shade}`, val as string); + }); + } + + // تنظیم فونت + if (theme.font) { + html.style.setProperty("--app-font", theme.font); + const fontId = `font-${theme.font}`; + if (!document.getElementById(fontId)) { + const style = document.createElement("style"); + style.id = fontId; + let rules = ""; + if (theme.fontFiles && Array.isArray(theme.fontFiles)) { + theme.fontFiles.forEach((f: any) => { + rules += ` + @font-face { + font-family: "${theme.font}"; + src: url("${f.src}") format("woff2"); + font-weight: ${f.weight}; + font-style: ${f.style}; + font-display: swap; + } + `; + }); + } + style.textContent = rules; + document.head.appendChild(style); + } + } + + // ست کردن لوگوها + if (theme.logo) { + if (theme.logo.light) + html.style.setProperty("--system-logo-light", theme.logo.light); + if (theme.logo.dark) + html.style.setProperty("--system-logo-dark", theme.logo.dark); + } + + // ارائه theme و key به اپ + return { + provide: { + themeKey: key, + theme, + }, + }; +}); + +``` + +### 10. stores/authStore.ts + +```typescript +// stores/authStore.ts +import { defineStore } from "pinia"; +import { useStorage } from "@vueuse/core"; + +export const useAuthStore = defineStore("authStore", () => { + // ===== state ===== + const user = ref({}); + const isAuthenticated = ref(false); + const isRealUser = ref(false); + const errors = ref(null); + const loading = ref(false); + + // ===== getters ===== + const isLoggedIn = computed(() => isAuthenticated.value && !!user.value?.token); + const userName = computed(() => { + if (!user.value) return ''; + return `${user.value.first_name || ''} ${user.value.last_name || ''}`.trim(); + }); + + // ===== actions ===== + function setUser(response: any) { + const payload = response?.data ?? response ?? {}; + + const userData = { + id: payload.user_id ?? payload.id ?? null, + level: payload.user_level ?? payload.level ?? null, + token: payload.token ?? null, + expire: payload.expire ?? null, + refresh_token: payload.refresh_token ?? null, + first_name: payload.first_name ?? payload.user_data?.first_name ?? '', + last_name: payload.last_name ?? payload.user_data?.last_name ?? '', + avatar: payload.avatar ?? payload.user_data?.avatar ?? '', + username: payload.username ?? payload.user_data?.username ?? '', + email: payload.email ?? payload.user_data?.email ?? '', + mobile: payload.mobile ?? payload.user_data?.mobile ?? '', + ...(payload.user_data || {}), + }; + + isAuthenticated.value = true; + isRealUser.value = true; + user.value = userData; + errors.value = null; + loading.value = false; + + // ذخیره در localStorage با استفاده از useStorage + try { + const tokenStorage = useStorage("id_token", ""); + tokenStorage.value = userData.token || ""; + + const userStorage = useStorage("user", {}); + userStorage.value = userData; + + const userIdStorage = useStorage("user_id", ""); + userIdStorage.value = String(userData.id || ""); + + // تنظیم توکن در http service + const nuxtApp = useNuxtApp(); + if (nuxtApp.$http && userData.token) { + nuxtApp.$http.setToken(userData.token); + } + } catch (e) { + console.warn("Could not write to storage:", e); + } + } + + async function login(credentials: { username: string; password: string; captcha?: string }) { + loading.value = true; + errors.value = null; + + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + const response = await $http.postRequest("/auth/login", credentials); + + if (response?.data || response?.token) { + setUser(response); + return { success: true, data: response }; + } + + throw new Error(response?.message || "ورود ناموفق بود"); + } catch (error: any) { + errors.value = error?.message || "خطا در ارتباط با سرور"; + loading.value = false; + return { success: false, error: errors.value }; + } + } + + async function getCaptcha() { + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + const response = await $http.getRequest("/auth/captcha"); + return response; + } catch (error) { + console.error("Captcha Error:", error); + return null; + } + } + + async function register(credentials: any) { + loading.value = true; + errors.value = null; + + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + const response = await $http.postRequest("/auth/register", credentials); + + if (response?.data || response?.token) { + setUser(response); + return { success: true, data: response }; + } + + throw new Error(response?.message || "ثبت نام ناموفق بود"); + } catch (error: any) { + errors.value = error?.message || "خطا در ثبت نام"; + loading.value = false; + return { success: false, error: errors.value }; + } + } + + async function logout() { + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + // تلاش برای logout از سرور + if (isAuthenticated.value) { + await $http.postRequest("/auth/logout", {}); + } + } catch (error) { + console.warn("Logout API error:", error); + } finally { + userReset(); + } + } + + function userReset() { + user.value = {}; + isAuthenticated.value = false; + isRealUser.value = false; + errors.value = null; + loading.value = false; + + // پاک کردن localStorage + try { + const tokenStorage = useStorage("id_token", ""); + tokenStorage.value = ""; + + const userStorage = useStorage("user", {}); + userStorage.value = {}; + + const userIdStorage = useStorage("user_id", ""); + userIdStorage.value = ""; + + // پاک کردن توکن از http service + const nuxtApp = useNuxtApp(); + if (nuxtApp.$http) { + nuxtApp.$http.clearToken(); + } + } catch (e) { + console.warn("Could not clear storage:", e); + } + } + + // بازیابی session از localStorage در شروع + const restoreSession = () => { + try { + const userStorage = useStorage("user", {}); + const storedUser = userStorage.value; + + if (storedUser && storedUser.token) { + user.value = storedUser; + isAuthenticated.value = true; + isRealUser.value = !!storedUser.id; + + // تنظیم توکن در http service + const nuxtApp = useNuxtApp(); + if (nuxtApp.$http && storedUser.token) { + nuxtApp.$http.setToken(storedUser.token); + } + } + } catch (e) { + console.warn("Could not restore session:", e); + } + }; + + // اجرای بازیابی session + if (process.client) { + restoreSession(); + } + + return { + // state + user, + isAuthenticated, + isRealUser, + errors, + loading, + + // getters + isLoggedIn, + userName, + + // actions + setUser, + login, + getCaptcha, + register, + logout, + userReset, + restoreSession, + }; +}); +``` + +### 11. stores/commonStore.ts + +```typescript +export const useCommonStore = defineStore("commonStore", () => { + const sidebarOpen = ref(false); + + function toggleSidebar() { + sidebarOpen.value = !sidebarOpen.value; + } + + function closeSidebar() { + sidebarOpen.value = false; + } + + return { + sidebarOpen, + toggleSidebar, + closeSidebar, + }; +}); + +``` + + +### 12. stores/permissionStore.ts + +```typescript +// stores/permissionStore.ts +import { defineStore } from "pinia"; +import { ref } from "vue"; +import { useAuthStore } from "./authStore"; +import { useStorage } from "@vueuse/core"; + +export const getUserPermission = defineStore("permissionStore", () => { + const permissions = ref([]); + const loading = ref(false); + + const hasPagePermission = (to_fullPath: string) => { + let index = to_fullPath.indexOf("?"); + if (index !== -1) to_fullPath = to_fullPath.substring(0, index); + + const items = to_fullPath.split("/"); + const page_key = items[1] + "_" + items[2]; + + return permissions.value.some((p) => p.section_tag === page_key); + }; + + const hasActionPermission = (to_fullPath: string, action_tag: string) => { + let index = to_fullPath.indexOf("?"); + if (index !== -1) to_fullPath = to_fullPath.substring(0, index); + + const items = to_fullPath.split("/"); + const page_key = items[1] + "_" + items[2]; + + return permissions.value.some( + (p) => p.section_tag === page_key && p.action_tag === action_tag + ); + }; + + const fetchUserPermissions = async (projectId?: number) => { + const { $http } = useNuxtApp(); + const authStore = useAuthStore(); + + if (!authStore.isAuthenticated && !localStorage.getItem("user")) { + console.log("No authenticated user found"); + return; + } + + loading.value = true; + + try { + const data = { + project_id: projectId || 50, + project_only: 1, + }; + + const response = await $http.postRequest("/permissions/user-permissions", data); + + permissions.value = response?.data || response || []; + + // ذخیره در localStorage برای استفاده بعدی + useStorage("permit", permissions.value); + } catch (error) { + console.error("❌ Failed to fetch user permissions:", error); + permissions.value = []; + } finally { + loading.value = false; + } + }; + + const reset = () => { + permissions.value = []; + loading.value = false; + }; + + return { + permissions, + loading, + hasPagePermission, + hasActionPermission, + fetchUserPermissions, + reset, + }; +}); +``` + +### 13. app.config.ts + +```typescript +export default defineAppConfig({ + ui: { + colors: { + primary: "primary", + secondary: "purple", + neutral: "zinc", + }, + button: { + slots: { + base: ["cursor-pointer"], + }, + defaultVariants: { + color: "primary", + variant: "solid", + // size حذف شد - پیش‌فرض Nuxt UI استفاده بشه + }, + }, + }, +}); +``` + + +### 15. app.vue + +```typescript + + + + +``` + + +### 14. .env + +```text +# .env (پایه) +NUXT_PUBLIC_SYSTEM=pakar +NUXT_PUBLIC_API_NAME=api/v1 + +# .env.monir +NUXT_PUBLIC_SYSTEM=monir +NUXT_PUBLIC_BASE_URL=http://192.168.23.60/ +NUXT_PUBLIC_API_NAME=api/v1 + +# .env.tavasi (اگر نیاز دارید) +NUXT_PUBLIC_SYSTEM=tavasi +NUXT_PUBLIC_BASE_URL=http://localhost:3000/ +NUXT_PUBLIC_API_NAME=api/v1 + +``` + + + +### 14. nuxt.config.ts + +```typescript +import { fileURLToPath } from "node:url"; + +export default defineNuxtConfig({ + compatibilityDate: "2025-07-15", + devtools: { enabled: false }, + // devtools: { enabled: true }, + ssr: false, // آفلاین بهتر با CSR + modules: ["@nuxt/ui", "@pinia/nuxt", "@nuxt/icon"], + css: ["~/assets/css/main.css"], + imports: { + dirs: ["stores", "composables", "apis"], + }, + colorMode: { + preference: "light", + fallback: "light", + classSuffix: "", + storageKey: "theme-mode", + }, + icon: { + serverBundle: { + collections: ["lucide", "system-uicons", "meteor-icons"], + }, + }, + ui: { + icons: { + collections: ["lucide", "system-uicons", "meteor-icons"], + }, + }, + components: [ + { + path: "~/components/auto-import", + extensions: ["vue"], + pathPrefix: false, + }, + ], + runtimeConfig: { + public: { + apiBase: "", // خالی برای آفلاین + wsUrl: "", + }, + }, + alias: { + "@": fileURLToPath(new URL("./app", import.meta.url)), + "@@": fileURLToPath(new URL(".", import.meta.url)), + "@/components": fileURLToPath(new URL("./app/components", import.meta.url)), + "@/composables": fileURLToPath( + new URL("./app/composables", import.meta.url), + ), + "@/layouts": fileURLToPath(new URL("./app/layouts", import.meta.url)), + "@/pages": fileURLToPath(new URL("./app/pages", import.meta.url)), + "@/plugins": fileURLToPath(new URL("./app/plugins", import.meta.url)), + "@/stores": fileURLToPath(new URL("./app/stores", import.meta.url)), + "@/assets": fileURLToPath(new URL("./app/assets", import.meta.url)), + "@/public": fileURLToPath(new URL("./public", import.meta.url)), + }, + // fonts: { providers: false }, ← حذف شد +}); + +``` + +### 15. package.json + +```json +{ + "name": "pakar", + "version": "1.0.0", + "description": "پروژه پاکار", + "type": "module", + "private": true, + "scripts": { + "build": "nuxt build", + "dev": "nuxt dev", + "dev-tavasi": "env-cmd -f .env.tavasi nuxt dev --host --port 3006 --inspect", + "dev-monir": "env-cmd -f .env.monir nuxt dev --host --port 3008 --inspect", + "build-monir": "env-cmd -f .env.monir nuxt build --host --inspect", + "build-db": "env-cmd -f .env.db nuxt build --host --inspect" + }, + "dependencies": { + "@fullcalendar/core": "^6.1.20", + "@fullcalendar/daygrid": "^6.1.20", + "@fullcalendar/interaction": "^6.1.20", + "@fullcalendar/list": "^6.1.20", + "@fullcalendar/timegrid": "^6.1.20", + "@fullcalendar/vue3": "^6.1.20", + "@iconify-json/meteor-icons": "^1.2.1", + "@nuxt/icon": "^2.2.1", + "@nuxt/ui": "^4.3.0", + "@nuxtjs/i18n": "^10.2.1", + "@pinia/nuxt": "^0.11.3", + "@tiptap/extension-drag-handle": "^3.20.0", + "@tiptap/extension-horizontal-rule": "^3.20.0", + "@tiptap/extension-link": "^3.20.0", + "@tiptap/extension-placeholder": "^3.20.0", + "@tiptap/extension-task-item": "^3.20.0", + "@tiptap/extension-task-list": "^3.20.0", + "@tiptap/extension-text-align": "^3.20.0", + "@tiptap/starter-kit": "^3.20.0", + "@tiptap/vue-3": "^3.20.0", + "@vuelidate/core": "^2.0.3", + "@vuelidate/validators": "^2.0.4", + "@vueuse/integrations": "^14.1.0", + "echarts": "^6.0.0", + "export-from-json": "^1.7.4", + "jalaali-js": "^1.2.8", + "lodash-es": "^4.17.22", + "mammoth": "^1.11.0", + "nuxt": "^4.2.1", + "ohmyfetch": "^0.4.21", + "pinia": "^3.0.4", + "sortablejs": "^1.15.6", + "sweetalert2": "^11.26.4", + "vite-tsconfig-paths": "^6.1.1", + "vue": "^3.5.25", + "vue-router": "^4.6.3", + "vue3-persian-datetime-picker": "^1.2.2" + }, + "devDependencies": { + "@iconify-json/lucide": "^1.2.86", + "env-cmd": "^11.0.0", + "sass": "^1.95.0", + "vue-draggable-next": "^2.3.0" + } +} + + +``` + +### 16. tailwind.config.js + +```javascript +/** @type {import('tailwindcss').Config} */ +export default { + darkMode: "class", + content: [], + theme: { + extend: {}, + }, + plugins: [], +}; + +``` + +### 17. tsconfig.json + +```json +{ + // https://nuxt.com/docs/guide/concepts/typescript + "files": [], + "references": [ + { + "path": "./.nuxt/tsconfig.app.json" + }, + { + "path": "./.nuxt/tsconfig.server.json" + }, + { + "path": "./.nuxt/tsconfig.shared.json" + }, + { + "path": "./.nuxt/tsconfig.node.json" + } + ] +} + +``` \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..206174c --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# پروژه پایه Nuxt 4 با قابلیت شخصی‌سازی تم، RTL، فونت و آیکون‌ها + +این ساختار پایه بر مبنای راهنمای [HELP.md](file:///d:/hamava/front/test/HELP.md) و تکنولوژی‌های روز شامل **Nuxt 4**، **Tailwind CSS** و **Nuxt UI** با قابلیت انعطاف‌پذیری و تم‌گذاری داینامیک طراحی و پیاده‌سازی شده است. + +--- + +## 🚀 ویژگی‌های کلیدی + +### ۱. معماری سیستم تم داینامیک (`composSystemTheme`) +از طریق کامپوزبل [`composSystemTheme`](file:///d:/hamava/front/test/app/composables/composSystemTheme.ts) و فایل پیکربندی [`theme.json`](file:///d:/hamava/front/test/app/assets/pakar/theme.json): +- **رنگ‌های اصلی (Primary Colors):** امکان تغییر رنگ اصلی برنامه به صورت زنده از طریق متدهای `setPrimaryColor(hex)` و `setPrimaryPalette(palette)` که متغیرهای CSS مانند `--color-primary-*` و متغیرهای سازگار با Nuxt UI را به طور بلادرنگ به‌روزرسانی می‌کند. +- **راست‌چین / چپ‌چین (RTL / LTR):** تنظیم پیش‌فرض جهت از فایل `theme.json` و امکان سوئیچ دوطرفه با متد `setDirection(boolean)` و `toggleDirection()`. +- **فونت پروژه (Font Family):** تنظیم فونت پروژه از فایل `theme.json` و تغییر آن در زمان اجرا با `setFont(fontName, fallback, files)` با تزریق خودکار قواعد `@font-face`. +- **مدیریت آیکون‌ها (Dynamic Icons):** بخش اختصاصی `icons` در `theme.json` برای نگاشت آیکون‌های استاندارد برنامه و تابع `getIcon(key)` و `setIcon(key, iconClass)`. +- **حالت روز / شب (Dark / Light Mode):** ذخیره خودکار در `localStorage` و اعمال کلاس `dark` روی تگ ``. + +### ۲. سرویس ارتباط با سرور (`httpService.ts`) +پلاگین [`httpService.ts`](file:///d:/hamava/front/test/app/plugins/httpService.ts) مبتنی بر `$fetch` نیترو طراحی شده و امکانات زیر را فراهم می‌کند: +- متدهای استاندارد: `getRequest`, `postRequest`, `putRequest`, `patchRequest`, `deleteRequest` +- اتصال خودکار توکن احراز هویت با `Authorization: Bearer ` +- مدیریت توکن با `setToken`, `clearToken`, `getToken` و یکپارچگی با [`authStore`](file:///d:/hamava/front/test/app/stores/authStore.ts) +- مدیریت خودکار خطای ۴۰۱ و ریدایرکت به صفحه لاگین + +--- + +## 🛠️ دستورات اجرایی + +```bash +# اجرای پروژه در محیط توسعه (Dev Server) +npm run dev + +# بیلد نهایی برای محیط پروداکشن +npm run build + +# اجرای پیش‌نمایش بیلد +node .output/server/index.mjs +``` diff --git a/app/app.config.ts b/app/app.config.ts new file mode 100644 index 0000000..ad93117 --- /dev/null +++ b/app/app.config.ts @@ -0,0 +1,18 @@ +export default defineAppConfig({ + ui: { + colors: { + primary: "primary", + secondary: "purple", + neutral: "zinc", + }, + button: { + slots: { + base: ["cursor-pointer"], + }, + defaultVariants: { + color: "primary", + variant: "solid", + }, + }, + }, +}); diff --git a/app/app.vue b/app/app.vue new file mode 100644 index 0000000..05e4cfa --- /dev/null +++ b/app/app.vue @@ -0,0 +1,47 @@ + + + diff --git a/app/assets/css/main.css b/app/assets/css/main.css new file mode 100644 index 0000000..2a2578a --- /dev/null +++ b/app/assets/css/main.css @@ -0,0 +1,116 @@ +@import "tailwindcss"; +@import "@nuxt/ui"; + +/* تعریف فونت‌های محلی از پوشه public */ +@font-face { + font-family: 'Vazirmatn'; + src: url('/fonts/vazir/Vazirmatn-Regular.woff2') format('woff2'); + font-weight: 400; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Vazirmatn'; + src: url('/fonts/vazir/Vazirmatn-Medium.woff2') format('woff2'); + font-weight: 500; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Vazirmatn'; + src: url('/fonts/vazir/Vazirmatn-Bold.woff2') format('woff2'); + font-weight: 700; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Sahel'; + src: url('/fonts/sahel/Sahel.woff2') format('woff2'); + font-weight: 400; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Sahel'; + src: url('/fonts/sahel/Sahel-Bold.woff2') format('woff2'); + font-weight: 700; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'Yekan'; + src: url('/fonts/Yekan/Yekan.woff2') format('woff2'); + font-weight: 400; + font-style: normal; + font-display: swap; +} + +@theme static { + /* Light colors */ + --color-light-primary: #ffffff; + --color-text__orange: #d99058; + --color-link-color: #c37943; + + /* Dark colors */ + --color-dark-primary: #111827; + --color-dark-primary-800: #1f2937; + --color-dark-primary-700: #374151; + --color-dark-primary-600: #4b5563; + --color-dark-primary-500: #6b7280; + --color-dark-primary-400: #9ca3af; + --color-dark-primary-300: #d1d5db; + --color-dark-primary-200: #e5e7eb; + --color-dark-primary-100: #f3f4f6; + --color-dark-primary-50: #f9fafb; + + /* Text colors */ + --color-white-normal: #ffffff; + --color-black-normal: #111827; + --color-white-bold: #ffffff; + --color-white-light: rgba(255, 255, 255, 0.6); + --color-white-strong: #ffffff; + --color-dark-normal: #e5e7eb; + --color-dark-bold: #111827; + --color-dark-light: #6b7280; + --color-dark-strong: #ffffff; + --color-text-disabled: #9ca3af; + --color-text-orange: #d99058; +} + +:root { + --app-font: 'Vazirmatn', 'Sahel', 'Yekan', system-ui, -apple-system, sans-serif; + --color-primary: #d99058; + --color-primary-50: #fbf6f1; + --color-primary-100: #f6ece1; + --color-primary-200: #ebd7c3; + --color-primary-300: #dfbfa1; + --color-primary-400: #d4a37b; + --color-primary-500: #d99058; + --color-primary-600: #c37943; + --color-primary-700: #a35f34; + --color-primary-800: #834c2b; + --color-primary-900: #6b3f25; + --color-primary-950: #391f11; + --ui-primary: #d99058; +} + +* { + font-family: var(--app-font, 'Vazirmatn', sans-serif); +} + +html, +body, +#__nuxt, +.root { + font-family: var(--app-font, 'Vazirmatn', sans-serif); +} + +button, +a { + cursor: pointer; +} diff --git a/app/assets/hamyar/theme.json b/app/assets/hamyar/theme.json new file mode 100644 index 0000000..7e78c8f --- /dev/null +++ b/app/assets/hamyar/theme.json @@ -0,0 +1,37 @@ +{ + "name": "سامانه همیار حوزه", + "title": "سامانه مدیریت و خدمات همیار", + "subTitle": "مرکز خدمات و پشتیبانی مدارس علمیه", + "description": "پرتال جامع خدمات، پشتیبانی و امور رفاهی طلاب و اساتید", + "version": "1.0.0", + "logo": { + "light": "/logo/hamyar/light_logo.png", + "dark": "/logo/hamyar/dark_logo.png", + "favicon": "/favicon.ico", + "icon": "/logo/hamyar/light_logo.png" + }, + "font": "Sahel", + "fontFallback": "'Vazirmatn', system-ui, Tahoma, sans-serif", + "colors": { + "primary": { + "50": "#eff6ff", + "100": "#dbeafe", + "200": "#bfdbfe", + "300": "#93c5fd", + "400": "#60a5fa", + "500": "#3b82f6", + "600": "#2563eb", + "700": "#1d4ed8", + "800": "#1e40af", + "900": "#1e3a8a", + "950": "#172554" + } + }, + "rtl": true, + "direction": "rtl", + "darkMode": { + "enabled": true, + "default": "light", + "storageKey": "theme-mode" + } +} diff --git a/app/assets/school/theme.json b/app/assets/school/theme.json new file mode 100644 index 0000000..f7aa196 --- /dev/null +++ b/app/assets/school/theme.json @@ -0,0 +1,103 @@ +{ + "name": "حوزه علمیه سفیران هدایت", + "title": "مدرسه علمیه سفیران هدایت", + "subTitle": "سامانه جامع آموزشی، تهذیبی و پژوهشی طلاب", + "description": "پرتال جامع اطلاع‌رسانی، امور آموزشی، پژوهش و خدمات طلاب حوزه علمیه سفیران هدایت", + "version": "1.0.0", + "logo": { + "light": "/logo/school/light_logo.png", + "dark": "/logo/school/dark_logo.png", + "favicon": "/favicon.ico", + "icon": "/logo/school/light_logo.png" + }, + "font": "Vazirmatn", + "fontFallback": "'Sahel', 'Yekan', system-ui, Tahoma, sans-serif", + "fontFiles": [ + { + "weight": "400", + "style": "normal", + "src": "/fonts/vazir/Vazirmatn-Regular.woff2" + }, + { + "weight": "500", + "style": "normal", + "src": "/fonts/vazir/Vazirmatn-Medium.woff2" + }, + { + "weight": "700", + "style": "normal", + "src": "/fonts/vazir/Vazirmatn-Bold.woff2" + }, + { + "weight": "400", + "style": "normal", + "src": "/fonts/sahel/Sahel.woff2" + }, + { + "weight": "700", + "style": "normal", + "src": "/fonts/sahel/Sahel-Bold.woff2" + }, + { + "weight": "400", + "style": "normal", + "src": "/fonts/Yekan/Yekan.woff2" + } + ], + "colors": { + "primary": { + "50": "#fbf6f1", + "100": "#f6ece1", + "200": "#ebd7c3", + "300": "#dfbfa1", + "400": "#d4a37b", + "500": "#d99058", + "600": "#c37943", + "700": "#a35f34", + "800": "#834c2b", + "900": "#6b3f25", + "950": "#391f11" + } + }, + "rtl": true, + "direction": "rtl", + "icons": { + "sun": "i-lucide-sun", + "moon": "i-lucide-moon", + "menu": "i-lucide-menu", + "close": "i-lucide-x", + "check": "i-lucide-check", + "chevronRight": "i-lucide-chevron-right", + "chevronLeft": "i-lucide-chevron-left", + "search": "i-lucide-search", + "user": "i-lucide-user", + "palette": "i-lucide-palette", + "font": "i-lucide-type", + "direction": "i-lucide-arrow-left-right", + "network": "i-lucide-wifi", + "settings": "i-lucide-settings", + "bell": "i-lucide-bell", + "dashboard": "i-lucide-layout-dashboard", + "logout": "i-lucide-log-out", + "bookOpen": "i-lucide-book-open", + "graduationCap": "i-lucide-graduation-cap", + "users": "i-lucide-users", + "calendar": "i-lucide-calendar", + "award": "i-lucide-award", + "library": "i-lucide-library", + "fileText": "i-lucide-file-text", + "phone": "i-lucide-phone", + "mapPin": "i-lucide-map-pin" + }, + "layout": { + "containerWidth": "1280px", + "sidebarWidth": "280px", + "headerHeight": "64px", + "footerHeight": "80px" + }, + "darkMode": { + "enabled": true, + "default": "light", + "storageKey": "theme-mode" + } +} diff --git a/app/components/auto-import/BaseModal.vue b/app/components/auto-import/BaseModal.vue new file mode 100644 index 0000000..9d35a27 --- /dev/null +++ b/app/components/auto-import/BaseModal.vue @@ -0,0 +1,178 @@ + + + diff --git a/app/components/auto-import/ConfirmModal.vue b/app/components/auto-import/ConfirmModal.vue new file mode 100644 index 0000000..b3003a0 --- /dev/null +++ b/app/components/auto-import/ConfirmModal.vue @@ -0,0 +1,33 @@ + + + diff --git a/app/composables/composSystemTheme.ts b/app/composables/composSystemTheme.ts new file mode 100644 index 0000000..29d9709 --- /dev/null +++ b/app/composables/composSystemTheme.ts @@ -0,0 +1,356 @@ +import { ref, computed } from "vue"; +import defaultSchoolTheme from "~/assets/school/theme.json"; + +export interface ThemeFontFile { + weight: string; + style: string; + src: string; +} + +export interface ThemeColors { + primary?: Record; + secondary?: Record; + [key: string]: Record | undefined; +} + +export interface ThemeConfig { + name?: string; + title?: string; + subTitle?: string; + description?: string; + version?: string; + logo?: { + light?: string; + dark?: string; + favicon?: string; + icon?: string; + }; + font?: string; + fontFallback?: string; + fontFiles?: ThemeFontFile[]; + colors?: ThemeColors; + rtl?: boolean; + direction?: "rtl" | "ltr"; + icons?: Record; + layout?: { + containerWidth?: string; + sidebarWidth?: string; + headerHeight?: string; + footerHeight?: string; + }; + darkMode?: { + enabled?: boolean; + default?: "light" | "dark" | "system"; + storageKey?: string; + }; +} + +export function composSystemTheme() { + const nuxtApp = useNuxtApp(); + + // دسترسی به تم تزریق‌شده توسط پلاگین بر اساس NUXT_PUBLIC_SYSTEM یا تم پیش‌فرض school + const initialTheme: ThemeConfig = (nuxtApp.$theme as ThemeConfig) || defaultSchoolTheme; + + // وضعیت سراسری تم + const currentTheme = useState("system_theme", () => initialTheme); + const themeKey = useState("system_theme_key", () => (nuxtApp.$themeKey as string) || "school"); + const isDark = useState("system_is_dark", () => false); + const isRtl = useState("system_is_rtl", () => currentTheme.value?.rtl ?? true); + + // وضعیت reactive آیکون‌ها + const icons = useState>("system_icons", () => ({ + sun: "i-lucide-sun", + moon: "i-lucide-moon", + menu: "i-lucide-menu", + close: "i-lucide-x", + check: "i-lucide-check", + chevronRight: "i-lucide-chevron-right", + chevronLeft: "i-lucide-chevron-left", + search: "i-lucide-search", + user: "i-lucide-user", + palette: "i-lucide-palette", + font: "i-lucide-type", + direction: "i-lucide-arrow-left-right", + network: "i-lucide-wifi", + settings: "i-lucide-settings", + bell: "i-lucide-bell", + dashboard: "i-lucide-layout-dashboard", + logout: "i-lucide-log-out", + bookOpen: "i-lucide-book-open", + graduationCap: "i-lucide-graduation-cap", + users: "i-lucide-users", + calendar: "i-lucide-calendar", + award: "i-lucide-award", + library: "i-lucide-library", + fileText: "i-lucide-file-text", + phone: "i-lucide-phone", + mapPin: "i-lucide-map-pin", + ...(currentTheme.value?.icons || {}), + })); + + // جهت صفحه + const direction = computed(() => (isRtl.value ? "rtl" : "ltr")); + + // لوگوی متناسب با تم روز/شب + const logo = computed(() => { + if (!currentTheme.value?.logo) return ""; + return isDark.value + ? currentTheme.value.logo.dark || currentTheme.value.logo.light || "" + : currentTheme.value.logo.light || currentTheme.value.logo.dark || ""; + }); + + // رنگ اصلی جاری (shade 500) + const primaryColor = computed(() => { + return currentTheme.value?.colors?.primary?.["500"] || "#d99058"; + }); + + // پالت کامل رنگ اصلی + const primaryPalette = computed(() => { + return currentTheme.value?.colors?.primary || {}; + }); + + // نام فونت جاری + const fontName = computed(() => { + return currentTheme.value?.font || "Vazirmatn"; + }); + + // متد استخراج آیکون + const getIcon = (key: string, fallback = "i-lucide-circle"): string => { + return icons.value[key] || fallback; + }; + + // تغییر یک آیکون + const setIcon = (key: string, iconClass: string) => { + icons.value = { + ...icons.value, + [key]: iconClass, + }; + if (currentTheme.value.icons) { + currentTheme.value.icons[key] = iconClass; + } + }; + + // به‌روزرسانی گروهی آیکون‌ها + const setIcons = (newIcons: Record) => { + icons.value = { + ...icons.value, + ...newIcons, + }; + currentTheme.value.icons = { + ...(currentTheme.value.icons || {}), + ...newIcons, + }; + }; + + // تغییر دارک مود + const toggleDarkMode = () => { + setDarkMode(!isDark.value); + }; + + const setDarkMode = (dark: boolean) => { + isDark.value = dark; + if (import.meta.client) { + const storageKey = currentTheme.value?.darkMode?.storageKey || "theme-mode"; + localStorage.setItem(storageKey, dark ? "dark" : "light"); + const root = document.documentElement; + if (dark) { + root.classList.add("dark"); + } else { + root.classList.remove("dark"); + } + } + }; + + // تغییر جهت RTL / LTR + const toggleDirection = () => { + setDirection(!isRtl.value); + }; + + const setDirection = (rtl: boolean) => { + isRtl.value = rtl; + currentTheme.value.rtl = rtl; + currentTheme.value.direction = rtl ? "rtl" : "ltr"; + if (import.meta.client) { + const root = document.documentElement; + root.setAttribute("dir", rtl ? "rtl" : "ltr"); + root.style.direction = rtl ? "rtl" : "ltr"; + } + }; + + // تولید پالت رنگی داینامیک از روی یک رنگ hex + const generateShades = (hex: string): Record => { + return { + "50": hex, + "100": hex, + "200": hex, + "300": hex, + "400": hex, + "500": hex, + "600": hex, + "700": hex, + "800": hex, + "900": hex, + "950": hex, + }; + }; + + // تغییر پالت رنگ primary + const setPrimaryPalette = (palette: Record) => { + if (!currentTheme.value.colors) { + currentTheme.value.colors = {}; + } + currentTheme.value.colors.primary = palette; + + if (import.meta.client) { + const root = document.documentElement; + Object.entries(palette).forEach(([shade, val]) => { + root.style.setProperty(`--color-primary-${shade}`, val); + root.style.setProperty(`--ui-color-primary-${shade}`, val); + }); + if (palette["500"]) { + root.style.setProperty("--color-primary", palette["500"]); + root.style.setProperty("--ui-primary", palette["500"]); + } + } + }; + + // تغییر رنگ اصلی فقط با ارسال کد رنگ + const setPrimaryColor = (hex: string) => { + const defaultShades = currentTheme.value?.colors?.primary; + const newShades = defaultShades ? { ...defaultShades, "500": hex, "600": hex } : generateShades(hex); + newShades["500"] = hex; + setPrimaryPalette(newShades); + }; + + // تغییر فونت پروژه + const setFont = (fontFamily: string, fallback?: string, fontFiles?: ThemeFontFile[]) => { + currentTheme.value.font = fontFamily; + if (fallback) currentTheme.value.fontFallback = fallback; + if (fontFiles) currentTheme.value.fontFiles = fontFiles; + + if (import.meta.client) { + const root = document.documentElement; + const fullFont = fallback ? `"${fontFamily}", ${fallback}` : `"${fontFamily}", sans-serif`; + root.style.setProperty("--app-font", fullFont); + + if (fontFiles && fontFiles.length > 0) { + const fontStyleId = `font-style-${fontFamily.replace(/\s+/g, "-")}`; + let styleEl = document.getElementById(fontStyleId) as HTMLStyleElement | null; + if (!styleEl) { + styleEl = document.createElement("style"); + styleEl.id = fontStyleId; + document.head.appendChild(styleEl); + } + let cssRules = ""; + fontFiles.forEach((f) => { + cssRules += ` + @font-face { + font-family: "${fontFamily}"; + src: url("${f.src}") format("woff2"); + font-weight: ${f.weight || "normal"}; + font-style: ${f.style || "normal"}; + font-display: swap; + } + `; + }); + styleEl.textContent = cssRules; + } + } + }; + + // اعمال جامع تم روی DOM و متغیرهای CSS + const applyTheme = async (newThemeConfig?: ThemeConfig) => { + if (newThemeConfig) { + currentTheme.value = { ...currentTheme.value, ...newThemeConfig }; + } + const theme = currentTheme.value; + + if (import.meta.client) { + const root = document.documentElement; + + // 1. تنظیم RTL / Direction + const rtl = theme.rtl ?? (theme.direction === "rtl"); + isRtl.value = rtl; + root.setAttribute("dir", rtl ? "rtl" : "ltr"); + root.style.direction = rtl ? "rtl" : "ltr"; + + // 2. تنظیم رنگ‌های Primary + if (theme.colors?.primary) { + Object.entries(theme.colors.primary).forEach(([shade, val]) => { + root.style.setProperty(`--color-primary-${shade}`, val); + root.style.setProperty(`--ui-color-primary-${shade}`, val); + }); + if (theme.colors.primary["500"]) { + root.style.setProperty("--color-primary", theme.colors.primary["500"]); + root.style.setProperty("--ui-primary", theme.colors.primary["500"]); + } + } + + // 3. تنظیم فونت + if (theme.font) { + setFont(theme.font, theme.fontFallback, theme.fontFiles); + } + + // 4. تنظیم ابعاد Layout + if (theme.layout) { + if (theme.layout.containerWidth) root.style.setProperty("--container-width", theme.layout.containerWidth); + if (theme.layout.sidebarWidth) root.style.setProperty("--sidebar-width", theme.layout.sidebarWidth); + if (theme.layout.headerHeight) root.style.setProperty("--header-height", theme.layout.headerHeight); + if (theme.layout.footerHeight) root.style.setProperty("--footer-height", theme.layout.footerHeight); + } + + // 5. تنظیم آیکون‌ها + if (theme.icons) { + setIcons(theme.icons); + } + + // 6. همگام‌سازی دارک مود + const storageKey = theme.darkMode?.storageKey || "theme-mode"; + const savedDark = localStorage.getItem(storageKey); + if (savedDark !== null) { + setDarkMode(savedDark === "dark"); + } else if (theme.darkMode?.default === "dark") { + setDarkMode(true); + } + } + + return currentTheme.value; + }; + + // سوئیچ داینامیک به تم یک پروژه دیگر + const switchSystemTheme = (newSystemKey: string) => { + const allThemes = (nuxtApp.$allThemes as Record) || {}; + if (allThemes[newSystemKey]) { + themeKey.value = newSystemKey; + applyTheme(allThemes[newSystemKey]); + } + }; + + return { + // Reactive State + currentTheme, + themeKey, + isDark, + isRtl, + direction, + logo, + fontName, + primaryColor, + primaryPalette, + icons, + + // Methods + applyTheme, + switchSystemTheme, + toggleDarkMode, + setDarkMode, + toggleDirection, + setDirection, + setPrimaryColor, + setPrimaryPalette, + setFont, + getIcon, + setIcon, + setIcons, + }; +} diff --git a/app/composables/useConfirm.ts b/app/composables/useConfirm.ts new file mode 100644 index 0000000..5839bc0 --- /dev/null +++ b/app/composables/useConfirm.ts @@ -0,0 +1,52 @@ +import { reactive, readonly } from "vue"; + +// یک state مشترک برای تمام کامپوننت‌ها +const confirmState = reactive({ + isOpen: false, + title: "تأیید عملیات", + message: "آیا از انجام این عملیات اطمینان دارید؟", + confirmText: "تأیید", + cancelText: "انصراف", + resolve: null as ((value: boolean) => void) | null, +}); + +export const useConfirmState = () => readonly(confirmState); + +export const useConfirm = () => { + const ucoShowConfirmModal = ( + options: { + title?: string; + message?: string; + confirmText?: string; + cancelText?: string; + } = {} + ): Promise => { + confirmState.title = options.title || "تأیید عملیات"; + confirmState.message = options.message || "آیا از انجام این عملیات اطمینان دارید؟"; + confirmState.confirmText = options.confirmText || "تأیید"; + confirmState.cancelText = options.cancelText || "انصراف"; + confirmState.isOpen = true; + + return new Promise((resolve) => { + confirmState.resolve = resolve; + }); + }; + + return { ucoShowConfirmModal }; +}; + +export const useConfirmActions = () => { + const ucoConfirm = () => { + confirmState.isOpen = false; + if (confirmState.resolve) confirmState.resolve(true); + confirmState.resolve = null; + }; + + const ucoCancelConfirmModal = () => { + confirmState.isOpen = false; + if (confirmState.resolve) confirmState.resolve(false); + confirmState.resolve = null; + }; + + return { ucoConfirm, ucoCancelConfirmModal }; +}; diff --git a/app/layouts/default.vue b/app/layouts/default.vue new file mode 100644 index 0000000..2cbf7c4 --- /dev/null +++ b/app/layouts/default.vue @@ -0,0 +1,180 @@ + + + diff --git a/app/pages/index.vue b/app/pages/index.vue new file mode 100644 index 0000000..980ba8b --- /dev/null +++ b/app/pages/index.vue @@ -0,0 +1,505 @@ + + + diff --git a/app/plugins/00-themeLoader.client.ts b/app/plugins/00-themeLoader.client.ts new file mode 100644 index 0000000..dfa0623 --- /dev/null +++ b/app/plugins/00-themeLoader.client.ts @@ -0,0 +1,37 @@ +import schoolTheme from "~/assets/school/theme.json"; +import { composSystemTheme } from "~/composables/composSystemTheme"; + +// بارگذاری خودکار تمام فایل‌های theme.json موجود در پوشه assets/* +const themeModules = import.meta.glob>("~/assets/*/theme.json", { + eager: true, + import: "default", +}); + +export const themes: Record = { + school: schoolTheme, +}; + +// نگاشت تمام پروژه‌ها بر اساس نام پوشه (school, hamyar, ...) +for (const [path, moduleContent] of Object.entries(themeModules)) { + const match = path.match(/assets\/([^/]+)\/theme\.json/); + if (match && match[1]) { + themes[match[1]] = moduleContent; + } +} + +export default defineNuxtPlugin(async (nuxtApp) => { + const config = useRuntimeConfig(); + // کلید سیستم از فایل .env فعال (پیش‌فرض: school) + const systemKey = (config.public.NUXT_PUBLIC_SYSTEM as string) || "school"; + const theme = themes[systemKey] || themes.school || schoolTheme; + + // ارائه به تمام کانتکست‌های Nuxt + nuxtApp.provide("theme", theme); + nuxtApp.provide("themeKey", systemKey); + nuxtApp.provide("allThemes", themes); + + if (import.meta.client) { + const systemTheme = composSystemTheme(); + await systemTheme.applyTheme(theme); + } +}); diff --git a/app/plugins/httpService.ts b/app/plugins/httpService.ts new file mode 100644 index 0000000..e55db25 --- /dev/null +++ b/app/plugins/httpService.ts @@ -0,0 +1,121 @@ +import { useStorage } from "@vueuse/core"; + +export default defineNuxtPlugin((nuxtApp) => { + // ====================== + // Runtime Config (Public) + // ====================== + const config = useRuntimeConfig(); + + const BASE_URL = (config.public.NUXT_PUBLIC_BASE_URL as string) || ""; + const API_NAME = (config.public.NUXT_PUBLIC_API_NAME as string) || ""; + + // ====================== + // Safe URL Joiner + // ====================== + const joinURL = (base: string, path: string) => { + if (!base) return path; + if (!path) return base; + return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`; + }; + + const baseURL = joinURL(BASE_URL, API_NAME); + + // ====================== + // Reactive Token + // ====================== + const token = useStorage("id_token", ""); + + // ====================== + // Fetch Instance + // ====================== + const api = $fetch.create({ + baseURL, + + // ====================== + // Request Interceptor + // ====================== + onRequest({ options }) { + const auth = token.value; + if (!auth) return; + const headers = (options.headers ||= {}); + if (headers instanceof Headers) { + headers.set("Authorization", `Bearer ${auth}`); + } else if (Array.isArray(headers)) { + headers.push(["Authorization", `Bearer ${auth}`]); + } else { + (headers as Record).Authorization = `Bearer ${auth}`; + } + }, + + // ====================== + // Response Handler + // ====================== + onResponse({ response }) { + return response._data; + }, + + // ====================== + // Error Handler + // ====================== + async onResponseError({ response }) { + const status = response?.status; + + if (status === 401) { + token.value = ""; + if (import.meta.client) { + await nuxtApp.runWithContext(() => navigateTo("/login")); + } + } + + throw { + status, + message: + response?._data?.message || response?.statusText || "خطای نامشخص در ارتباط با سرور", + data: response?._data || null, + }; + }, + }); + + // ====================== + // HTTP Service (Public API) + // ====================== + const http = { + getRequest: (url: string, options: any = {}) => + api(url, { method: "GET", ...options }), + + postRequest: (url: string, body?: any, options: any = {}) => + api(url, { method: "POST", body, ...options }), + + putRequest: (url: string, body?: any, options: any = {}) => + api(url, { method: "PUT", body, ...options }), + + patchRequest: (url: string, body?: any, options: any = {}) => + api(url, { method: "PATCH", body, ...options }), + + deleteRequest: (url: string, options: any = {}) => + api(url, { method: "DELETE", ...options }), + + // متدهای مدیریت توکن که در authStore استفاده می‌شوند + setToken: (newToken: string) => { + token.value = newToken; + }, + + clearToken: () => { + token.value = ""; + }, + + getToken: () => token.value, + + // دسترسی مستقیم به کلاینت خام Fetch + raw: api, + }; + + // ====================== + // Provide to Nuxt + // ====================== + return { + provide: { + http, + }, + }; +}); diff --git a/app/stores/authStore.ts b/app/stores/authStore.ts new file mode 100644 index 0000000..b36c1e5 --- /dev/null +++ b/app/stores/authStore.ts @@ -0,0 +1,202 @@ +import { defineStore } from "pinia"; +import { ref, computed } from "vue"; +import { useStorage } from "@vueuse/core"; + +export const useAuthStore = defineStore("authStore", () => { + // ===== state ===== + const user = ref({}); + const isAuthenticated = ref(false); + const isRealUser = ref(false); + const errors = ref(null); + const loading = ref(false); + + // ===== getters ===== + const isLoggedIn = computed(() => isAuthenticated.value && !!user.value?.token); + const userName = computed(() => { + if (!user.value) return ""; + return `${user.value.first_name || ""} ${user.value.last_name || ""}`.trim() || user.value.username || ""; + }); + + // ===== actions ===== + function setUser(response: any) { + const payload = response?.data ?? response ?? {}; + + const userData = { + id: payload.user_id ?? payload.id ?? null, + level: payload.user_level ?? payload.level ?? null, + token: payload.token ?? null, + expire: payload.expire ?? null, + refresh_token: payload.refresh_token ?? null, + first_name: payload.first_name ?? payload.user_data?.first_name ?? "", + last_name: payload.last_name ?? payload.user_data?.last_name ?? "", + avatar: payload.avatar ?? payload.user_data?.avatar ?? "", + username: payload.username ?? payload.user_data?.username ?? "", + email: payload.email ?? payload.user_data?.email ?? "", + mobile: payload.mobile ?? payload.user_data?.mobile ?? "", + ...(payload.user_data || {}), + }; + + isAuthenticated.value = true; + isRealUser.value = true; + user.value = userData; + errors.value = null; + loading.value = false; + + try { + const tokenStorage = useStorage("id_token", ""); + tokenStorage.value = userData.token || ""; + + const userStorage = useStorage("user", {}); + userStorage.value = userData; + + const userIdStorage = useStorage("user_id", ""); + userIdStorage.value = String(userData.id || ""); + + const nuxtApp = useNuxtApp(); + if (nuxtApp.$http && userData.token) { + nuxtApp.$http.setToken(userData.token); + } + } catch (e) { + console.warn("Could not write to storage:", e); + } + } + + async function login(credentials: { username: string; password: string; captcha?: string }) { + loading.value = true; + errors.value = null; + + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + const response = await $http.postRequest("/auth/login", credentials); + + if (response?.data || response?.token) { + setUser(response); + return { success: true, data: response }; + } + + throw new Error(response?.message || "ورود ناموفق بود"); + } catch (error: any) { + errors.value = error?.message || "خطا در ارتباط با سرور"; + loading.value = false; + return { success: false, error: errors.value }; + } + } + + async function getCaptcha() { + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + return await $http.getRequest("/auth/captcha"); + } catch (error) { + console.error("Captcha Error:", error); + return null; + } + } + + async function register(credentials: any) { + loading.value = true; + errors.value = null; + + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + const response = await $http.postRequest("/auth/register", credentials); + + if (response?.data || response?.token) { + setUser(response); + return { success: true, data: response }; + } + + throw new Error(response?.message || "ثبت نام ناموفق بود"); + } catch (error: any) { + errors.value = error?.message || "خطا در ثبت نام"; + loading.value = false; + return { success: false, error: errors.value }; + } + } + + async function logout() { + try { + const nuxtApp = useNuxtApp(); + const { $http } = nuxtApp; + + if (isAuthenticated.value) { + await $http.postRequest("/auth/logout", {}); + } + } catch (error) { + console.warn("Logout API error:", error); + } finally { + userReset(); + } + } + + function userReset() { + user.value = {}; + isAuthenticated.value = false; + isRealUser.value = false; + errors.value = null; + loading.value = false; + + try { + const tokenStorage = useStorage("id_token", ""); + tokenStorage.value = ""; + + const userStorage = useStorage("user", {}); + userStorage.value = {}; + + const userIdStorage = useStorage("user_id", ""); + userIdStorage.value = ""; + + const nuxtApp = useNuxtApp(); + if (nuxtApp.$http) { + nuxtApp.$http.clearToken(); + } + } catch (e) { + console.warn("Could not clear storage:", e); + } + } + + const restoreSession = () => { + try { + const userStorage = useStorage("user", {}); + const storedUser = userStorage.value as any; + + if (storedUser && storedUser.token) { + user.value = storedUser; + isAuthenticated.value = true; + isRealUser.value = !!storedUser.id; + + const nuxtApp = useNuxtApp(); + if (nuxtApp.$http && storedUser.token) { + nuxtApp.$http.setToken(storedUser.token); + } + } + } catch (e) { + console.warn("Could not restore session:", e); + } + }; + + if (import.meta.client) { + restoreSession(); + } + + return { + user, + isAuthenticated, + isRealUser, + errors, + loading, + isLoggedIn, + userName, + setUser, + login, + getCaptcha, + register, + logout, + userReset, + restoreSession, + }; +}); diff --git a/app/stores/commonStore.ts b/app/stores/commonStore.ts new file mode 100644 index 0000000..edc2d56 --- /dev/null +++ b/app/stores/commonStore.ts @@ -0,0 +1,25 @@ +import { defineStore } from "pinia"; +import { ref } from "vue"; + +export const useCommonStore = defineStore("commonStore", () => { + const sidebarOpen = ref(false); + + function toggleSidebar() { + sidebarOpen.value = !sidebarOpen.value; + } + + function closeSidebar() { + sidebarOpen.value = false; + } + + function openSidebar() { + sidebarOpen.value = true; + } + + return { + sidebarOpen, + toggleSidebar, + closeSidebar, + openSidebar, + }; +}); diff --git a/app/stores/permissionStore.ts b/app/stores/permissionStore.ts new file mode 100644 index 0000000..be5eda3 --- /dev/null +++ b/app/stores/permissionStore.ts @@ -0,0 +1,78 @@ +import { defineStore } from "pinia"; +import { ref } from "vue"; +import { useAuthStore } from "./authStore"; +import { useStorage } from "@vueuse/core"; + +export const getUserPermission = defineStore("permissionStore", () => { + const permissions = ref([]); + const loading = ref(false); + + const hasPagePermission = (to_fullPath: string) => { + let path = to_fullPath; + const index = path.indexOf("?"); + if (index !== -1) path = path.substring(0, index); + + const items = path.split("/"); + const page_key = (items[1] || "") + "_" + (items[2] || ""); + + return permissions.value.some((p) => p.section_tag === page_key); + }; + + const hasActionPermission = (to_fullPath: string, action_tag: string) => { + let path = to_fullPath; + const index = path.indexOf("?"); + if (index !== -1) path = path.substring(0, index); + + const items = path.split("/"); + const page_key = (items[1] || "") + "_" + (items[2] || ""); + + return permissions.value.some( + (p) => p.section_tag === page_key && p.action_tag === action_tag + ); + }; + + const fetchUserPermissions = async (projectId?: number) => { + const { $http } = useNuxtApp(); + const authStore = useAuthStore(); + + if (!authStore.isAuthenticated && import.meta.client && !localStorage.getItem("user")) { + return; + } + + loading.value = true; + + try { + const data = { + project_id: projectId || 50, + project_only: 1, + }; + + const response = await $http.postRequest("/permissions/user-permissions", data); + permissions.value = response?.data || response || []; + + if (import.meta.client) { + const permitStorage = useStorage("permit", []); + permitStorage.value = permissions.value; + } + } catch (error) { + console.warn("Could not fetch user permissions:", error); + permissions.value = []; + } finally { + loading.value = false; + } + }; + + const reset = () => { + permissions.value = []; + loading.value = false; + }; + + return { + permissions, + loading, + hasPagePermission, + hasActionPermission, + fetchUserPermissions, + reset, + }; +}); diff --git a/nuxt.config.ts b/nuxt.config.ts new file mode 100644 index 0000000..d17cde2 --- /dev/null +++ b/nuxt.config.ts @@ -0,0 +1,57 @@ +import { fileURLToPath } from "node:url"; + +export default defineNuxtConfig({ + compatibilityDate: "2025-07-15", + devtools: { enabled: false }, + ssr: false, + + modules: [ + "@nuxt/ui", + "@pinia/nuxt", + "@nuxt/icon", + ], + + css: ["~/assets/css/main.css"], + + imports: { + dirs: ["stores", "composables", "apis"], + }, + + colorMode: { + preference: "light", + fallback: "light", + classSuffix: "", + storageKey: "theme-mode", + }, + + icon: { + clientBundle: { + scan: true, + }, + }, + + components: [ + { + path: "~/components/auto-import", + extensions: ["vue"], + pathPrefix: false, + }, + { + path: "~/components", + extensions: ["vue"], + }, + ], + + runtimeConfig: { + public: { + NUXT_PUBLIC_SYSTEM: process.env.NUXT_PUBLIC_SYSTEM || "school", + NUXT_PUBLIC_BASE_URL: process.env.NUXT_PUBLIC_BASE_URL || "http://localhost:3000/", + NUXT_PUBLIC_API_NAME: process.env.NUXT_PUBLIC_API_NAME || "api/v1", + }, + }, + + alias: { + "@": fileURLToPath(new URL("./app", import.meta.url)), + "~": fileURLToPath(new URL("./app", import.meta.url)), + }, +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..42d52ee --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "school-system", + "version": "1.0.0", + "type": "module", + "private": true, + "scripts": { + "dev": "nuxt dev", + "dev:school": "env-cmd -f .env.school nuxt dev --port 3002", + "dev:hamyar": "env-cmd -f .env.hamyar nuxt dev --port 3001", + "build": "nuxt build", + "build:school": "env-cmd -f .env.school nuxt build", + "build:hamyar": "env-cmd -f .env.hamyar nuxt build", + "generate": "nuxt generate", + "preview": "nuxt preview", + "postinstall": "nuxt prepare" + }, + "dependencies": { + "@nuxt/icon": "^2.2.1", + "@nuxt/ui": "^4.12.0", + "@pinia/nuxt": "^0.11.3", + "@vueuse/core": "^14.1.0", + "nuxt": "^4.2.1", + "pinia": "^3.0.4", + "vue": "^3.5.25", + "vue-router": "^4.6.3" + }, + "devDependencies": { + "@iconify-json/lucide": "^1.2.86", + "env-cmd": "^11.0.0" + } +} diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000..18993ad Binary files /dev/null and b/public/favicon.ico differ diff --git a/public/fonts/Yekan/Yekan.eot b/public/fonts/Yekan/Yekan.eot new file mode 100644 index 0000000..eab8443 Binary files /dev/null and b/public/fonts/Yekan/Yekan.eot differ diff --git a/public/fonts/Yekan/Yekan.otf b/public/fonts/Yekan/Yekan.otf new file mode 100644 index 0000000..5d9a7df Binary files /dev/null and b/public/fonts/Yekan/Yekan.otf differ diff --git a/public/fonts/Yekan/Yekan.ttf b/public/fonts/Yekan/Yekan.ttf new file mode 100644 index 0000000..8b886d4 Binary files /dev/null and b/public/fonts/Yekan/Yekan.ttf differ diff --git a/public/fonts/Yekan/Yekan.woff b/public/fonts/Yekan/Yekan.woff new file mode 100644 index 0000000..f672da4 Binary files /dev/null and b/public/fonts/Yekan/Yekan.woff differ diff --git a/public/fonts/Yekan/Yekan.woff2 b/public/fonts/Yekan/Yekan.woff2 new file mode 100644 index 0000000..846ecc1 Binary files /dev/null and b/public/fonts/Yekan/Yekan.woff2 differ diff --git a/public/fonts/sahel/Sahel-Black.eot b/public/fonts/sahel/Sahel-Black.eot new file mode 100644 index 0000000..760dd39 Binary files /dev/null and b/public/fonts/sahel/Sahel-Black.eot differ diff --git a/public/fonts/sahel/Sahel-Black.ttf b/public/fonts/sahel/Sahel-Black.ttf new file mode 100644 index 0000000..5226fe5 Binary files /dev/null and b/public/fonts/sahel/Sahel-Black.ttf differ diff --git a/public/fonts/sahel/Sahel-Black.woff b/public/fonts/sahel/Sahel-Black.woff new file mode 100644 index 0000000..abc2df4 Binary files /dev/null and b/public/fonts/sahel/Sahel-Black.woff differ diff --git a/public/fonts/sahel/Sahel-Black.woff2 b/public/fonts/sahel/Sahel-Black.woff2 new file mode 100644 index 0000000..02bc77e Binary files /dev/null and b/public/fonts/sahel/Sahel-Black.woff2 differ diff --git a/public/fonts/sahel/Sahel-Bold.eot b/public/fonts/sahel/Sahel-Bold.eot new file mode 100644 index 0000000..b682f25 Binary files /dev/null and b/public/fonts/sahel/Sahel-Bold.eot differ diff --git a/public/fonts/sahel/Sahel-Bold.ttf b/public/fonts/sahel/Sahel-Bold.ttf new file mode 100644 index 0000000..107ba11 Binary files /dev/null and b/public/fonts/sahel/Sahel-Bold.ttf differ diff --git a/public/fonts/sahel/Sahel-Bold.woff b/public/fonts/sahel/Sahel-Bold.woff new file mode 100644 index 0000000..0243bb7 Binary files /dev/null and b/public/fonts/sahel/Sahel-Bold.woff differ diff --git a/public/fonts/sahel/Sahel-Bold.woff2 b/public/fonts/sahel/Sahel-Bold.woff2 new file mode 100644 index 0000000..ed30ea0 Binary files /dev/null and b/public/fonts/sahel/Sahel-Bold.woff2 differ diff --git a/public/fonts/sahel/Sahel-Light.eot b/public/fonts/sahel/Sahel-Light.eot new file mode 100644 index 0000000..6779927 Binary files /dev/null and b/public/fonts/sahel/Sahel-Light.eot differ diff --git a/public/fonts/sahel/Sahel-Light.ttf b/public/fonts/sahel/Sahel-Light.ttf new file mode 100644 index 0000000..83d19e3 Binary files /dev/null and b/public/fonts/sahel/Sahel-Light.ttf differ diff --git a/public/fonts/sahel/Sahel-Light.woff b/public/fonts/sahel/Sahel-Light.woff new file mode 100644 index 0000000..1d8ac7c Binary files /dev/null and b/public/fonts/sahel/Sahel-Light.woff differ diff --git a/public/fonts/sahel/Sahel-Light.woff2 b/public/fonts/sahel/Sahel-Light.woff2 new file mode 100644 index 0000000..6c9fd08 Binary files /dev/null and b/public/fonts/sahel/Sahel-Light.woff2 differ diff --git a/public/fonts/sahel/Sahel-SemiBold.eot b/public/fonts/sahel/Sahel-SemiBold.eot new file mode 100644 index 0000000..fcdf3e6 Binary files /dev/null and b/public/fonts/sahel/Sahel-SemiBold.eot differ diff --git a/public/fonts/sahel/Sahel-SemiBold.ttf b/public/fonts/sahel/Sahel-SemiBold.ttf new file mode 100644 index 0000000..4dc5000 Binary files /dev/null and b/public/fonts/sahel/Sahel-SemiBold.ttf differ diff --git a/public/fonts/sahel/Sahel-SemiBold.woff b/public/fonts/sahel/Sahel-SemiBold.woff new file mode 100644 index 0000000..e879c3b Binary files /dev/null and b/public/fonts/sahel/Sahel-SemiBold.woff differ diff --git a/public/fonts/sahel/Sahel-SemiBold.woff2 b/public/fonts/sahel/Sahel-SemiBold.woff2 new file mode 100644 index 0000000..cd4cfb8 Binary files /dev/null and b/public/fonts/sahel/Sahel-SemiBold.woff2 differ diff --git a/public/fonts/sahel/Sahel-VF.ttf b/public/fonts/sahel/Sahel-VF.ttf new file mode 100644 index 0000000..f66a9f9 Binary files /dev/null and b/public/fonts/sahel/Sahel-VF.ttf differ diff --git a/public/fonts/sahel/Sahel-VF.woff2 b/public/fonts/sahel/Sahel-VF.woff2 new file mode 100644 index 0000000..f29ad19 Binary files /dev/null and b/public/fonts/sahel/Sahel-VF.woff2 differ diff --git a/public/fonts/sahel/Sahel.eot b/public/fonts/sahel/Sahel.eot new file mode 100644 index 0000000..a07532b Binary files /dev/null and b/public/fonts/sahel/Sahel.eot differ diff --git a/public/fonts/sahel/Sahel.ttf b/public/fonts/sahel/Sahel.ttf new file mode 100644 index 0000000..3b65334 Binary files /dev/null and b/public/fonts/sahel/Sahel.ttf differ diff --git a/public/fonts/sahel/Sahel.woff b/public/fonts/sahel/Sahel.woff new file mode 100644 index 0000000..eb70bca Binary files /dev/null and b/public/fonts/sahel/Sahel.woff differ diff --git a/public/fonts/sahel/Sahel.woff2 b/public/fonts/sahel/Sahel.woff2 new file mode 100644 index 0000000..9a6a7cc Binary files /dev/null and b/public/fonts/sahel/Sahel.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-Black.ttf b/public/fonts/vazir/Vazirmatn-Black.ttf new file mode 100644 index 0000000..4b9bd66 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Black.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-Black.woff2 b/public/fonts/vazir/Vazirmatn-Black.woff2 new file mode 100644 index 0000000..f08cace Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Black.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-Bold.ttf b/public/fonts/vazir/Vazirmatn-Bold.ttf new file mode 100644 index 0000000..efa9b09 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Bold.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-Bold.woff2 b/public/fonts/vazir/Vazirmatn-Bold.woff2 new file mode 100644 index 0000000..65b427f Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Bold.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-ExtraBold.ttf b/public/fonts/vazir/Vazirmatn-ExtraBold.ttf new file mode 100644 index 0000000..380bd15 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-ExtraBold.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-ExtraBold.woff2 b/public/fonts/vazir/Vazirmatn-ExtraBold.woff2 new file mode 100644 index 0000000..c074e70 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-ExtraBold.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-ExtraLight.ttf b/public/fonts/vazir/Vazirmatn-ExtraLight.ttf new file mode 100644 index 0000000..b7b947e Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-ExtraLight.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-ExtraLight.woff2 b/public/fonts/vazir/Vazirmatn-ExtraLight.woff2 new file mode 100644 index 0000000..997dea0 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-ExtraLight.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-Light.ttf b/public/fonts/vazir/Vazirmatn-Light.ttf new file mode 100644 index 0000000..2dfd5c3 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Light.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-Light.woff2 b/public/fonts/vazir/Vazirmatn-Light.woff2 new file mode 100644 index 0000000..d154722 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Light.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-Medium.ttf b/public/fonts/vazir/Vazirmatn-Medium.ttf new file mode 100644 index 0000000..1e08dd5 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Medium.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-Medium.woff2 b/public/fonts/vazir/Vazirmatn-Medium.woff2 new file mode 100644 index 0000000..495af75 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Medium.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-Regular.ttf b/public/fonts/vazir/Vazirmatn-Regular.ttf new file mode 100644 index 0000000..64e4a81 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Regular.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-Regular.woff2 b/public/fonts/vazir/Vazirmatn-Regular.woff2 new file mode 100644 index 0000000..c9824c8 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Regular.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-SemiBold.ttf b/public/fonts/vazir/Vazirmatn-SemiBold.ttf new file mode 100644 index 0000000..6b3842a Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-SemiBold.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-SemiBold.woff2 b/public/fonts/vazir/Vazirmatn-SemiBold.woff2 new file mode 100644 index 0000000..5301641 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-SemiBold.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn-Thin.ttf b/public/fonts/vazir/Vazirmatn-Thin.ttf new file mode 100644 index 0000000..b7a7d23 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Thin.ttf differ diff --git a/public/fonts/vazir/Vazirmatn-Thin.woff2 b/public/fonts/vazir/Vazirmatn-Thin.woff2 new file mode 100644 index 0000000..b7df278 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn-Thin.woff2 differ diff --git a/public/fonts/vazir/Vazirmatn[wght].woff2 b/public/fonts/vazir/Vazirmatn[wght].woff2 new file mode 100644 index 0000000..a501289 Binary files /dev/null and b/public/fonts/vazir/Vazirmatn[wght].woff2 differ diff --git a/public/logo/hamyar/dark_logo.png b/public/logo/hamyar/dark_logo.png new file mode 100644 index 0000000..0b75d10 Binary files /dev/null and b/public/logo/hamyar/dark_logo.png differ diff --git a/public/logo/hamyar/light_logo.png b/public/logo/hamyar/light_logo.png new file mode 100644 index 0000000..1c2b02b Binary files /dev/null and b/public/logo/hamyar/light_logo.png differ diff --git a/public/logo/school/dark_logo.png b/public/logo/school/dark_logo.png new file mode 100644 index 0000000..0b75d10 Binary files /dev/null and b/public/logo/school/dark_logo.png differ diff --git a/public/logo/school/light_logo.png b/public/logo/school/light_logo.png new file mode 100644 index 0000000..1c2b02b Binary files /dev/null and b/public/logo/school/light_logo.png differ diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..0ad279c --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow: diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..a746f2a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,4 @@ +{ + // https://nuxt.com/docs/guide/concepts/typescript + "extends": "./.nuxt/tsconfig.json" +}