edit ios & api

This commit is contained in:
2026-06-13 16:49:49 +03:30
parent a2de345112
commit 10f1ef9185
7 changed files with 118 additions and 17 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<html lang="fa" dir="rtl"> <html lang="fa" dir="rtl">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<meta name="theme-color" content="#d97706" /> <meta name="theme-color" content="#d97706" />
<title>منتایم — پنل مدیریت</title> <title>منتایم — پنل مدیریت</title>
<link rel="icon" type="image/png" sizes="32x32" href="/icons/icon-32.png" /> <link rel="icon" type="image/png" sizes="32x32" href="/icons/icon-32.png" />
+7
View File
@@ -11,6 +11,13 @@ export type User = {
updatedAt?: string; updatedAt?: string;
}; };
export type CreateUserPayload = {
mobile: string;
fullName?: string | null;
role?: UserRole;
isActive?: boolean;
};
export type UpdateUserPayload = { export type UpdateUserPayload = {
fullName?: string | null; fullName?: string | null;
role?: UserRole; role?: UserRole;
+8 -1
View File
@@ -1,10 +1,17 @@
import { api } from './client'; import { api } from './client';
import type { AdminSetUserPasswordPayload, UpdateUserPayload, User } from './types'; import type { AdminSetUserPasswordPayload, CreateUserPayload, UpdateUserPayload, User } from './types';
export function fetchUsers() { export function fetchUsers() {
return api<User[]>('/users'); return api<User[]>('/users');
} }
export function createUser(payload: CreateUserPayload) {
return api<User>('/users', {
method: 'POST',
body: JSON.stringify(payload),
});
}
export function fetchUser(id: string) { export function fetchUser(id: string) {
return api<User>(`/users/${id}`); return api<User>(`/users/${id}`);
} }
+6 -4
View File
@@ -1,7 +1,9 @@
<template> <template>
<div <div class="app-shell-root min-h-[100dvh] w-full bg-surface-2">
class="mx-auto flex min-h-dvh w-full max-w-app flex-col bg-surface shadow-xl shadow-black/5 dark:shadow-black/30" <div
> class="app-shell-frame mx-auto flex h-[100dvh] max-h-[100dvh] w-full min-w-0 max-w-full flex-col overflow-hidden bg-surface shadow-xl shadow-black/5 dark:shadow-black/30 max-w-app"
<slot /> >
<slot />
</div>
</div> </div>
</template> </template>
+3 -3
View File
@@ -1,7 +1,7 @@
<template> <template>
<AppShell> <AppShell>
<header <header
class="sticky top-0 z-10 flex items-center justify-between border-b border-brand-500/30 bg-surface/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-surface/80" class="z-10 flex shrink-0 items-center justify-between border-b border-brand-500/30 bg-surface/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-surface/80 pt-[max(0.75rem,env(safe-area-inset-top))]"
> >
<RouterLink :to="{ name: 'dashboard' }" class="flex min-w-0 items-center gap-2"> <RouterLink :to="{ name: 'dashboard' }" class="flex min-w-0 items-center gap-2">
<AppLogo variant="horizontal" class="h-10 shrink-0" /> <AppLogo variant="horizontal" class="h-10 shrink-0" />
@@ -33,12 +33,12 @@
</div> </div>
</header> </header>
<main class="flex-1 space-y-4 px-4 py-4 pb-6"> <main class="min-h-0 flex-1 space-y-4 overflow-y-auto overscroll-y-contain px-4 py-4 pb-6 [-webkit-overflow-scrolling:touch]">
<slot /> <slot />
</main> </main>
<nav <nav
class="sticky bottom-0 z-10 shrink-0 border-t border-border bg-surface/95 px-1 py-2 backdrop-blur supports-[backdrop-filter]:bg-surface/80" class="z-10 shrink-0 border-t border-border bg-surface/95 px-1 py-2 backdrop-blur supports-[backdrop-filter]:bg-surface/80 pb-[max(0.5rem,env(safe-area-inset-bottom))]"
> >
<div class="flex gap-0.5"> <div class="flex gap-0.5">
<RouterLink <RouterLink
+24
View File
@@ -26,6 +26,28 @@
html { html {
@apply antialiased font-sans; @apply antialiased font-sans;
font-family: IRANYekanX, ui-sans-serif, system-ui, sans-serif; font-family: IRANYekanX, ui-sans-serif, system-ui, sans-serif;
height: 100%;
overflow: hidden;
}
@supports (-webkit-touch-callout: none) {
html,
body,
#app {
height: 100%;
overflow: hidden;
}
.app-shell-root {
min-height: 100%;
min-height: -webkit-fill-available;
}
.app-shell-frame {
height: 100%;
max-height: 100%;
min-height: -webkit-fill-available;
}
} }
body, body,
@@ -42,5 +64,7 @@
#app { #app {
min-height: 100dvh; min-height: 100dvh;
height: 100%;
overflow: hidden;
} }
} }
+69 -8
View File
@@ -1,6 +1,10 @@
<template> <template>
<AdminLayout> <AdminLayout>
<PageHeader title="کاربران" subtitle="مدیریت نقش و وضعیت کاربران" /> <PageHeader title="کاربران" subtitle="مدیریت نقش و وضعیت کاربران">
<template #actions>
<AppButton class="!w-auto shrink-0 px-4" @click="openCreate">جدید</AppButton>
</template>
</PageHeader>
<SearchInput <SearchInput
v-model="searchQuery" v-model="searchQuery"
@@ -49,9 +53,19 @@
</li> </li>
</ul> </ul>
<AppModal :open="!!editing" title="ویرایش کاربر" @close="closeEdit"> <AppModal :open="creating || !!editing" :title="creating ? 'کاربر جدید' : 'ویرایش کاربر'" @close="closeEdit">
<form v-if="editing" class="space-y-4" @submit.prevent="onSave"> <form v-if="creating || editing" class="space-y-4" @submit.prevent="onSave">
<p class="text-sm text-muted" dir="ltr">{{ editing.mobile }}</p> <AppInput
v-if="creating"
id="userMobile"
v-model="form.mobile"
label="شماره موبایل"
ltr
inputmode="tel"
placeholder="09121234567"
required
/>
<p v-else class="text-sm text-muted" dir="ltr">{{ editing?.mobile }}</p>
<AppInput id="userFullName" v-model="form.fullName" label="نام" /> <AppInput id="userFullName" v-model="form.fullName" label="نام" />
@@ -67,9 +81,9 @@
حساب فعال است حساب فعال است
</label> </label>
<section class="space-y-3 rounded-xl border border-border bg-surface-3 p-3"> <section v-if="!creating" class="space-y-3 rounded-xl border border-border bg-surface-3 p-3">
<h3 class="text-sm font-semibold text-text"> <h3 class="text-sm font-semibold text-text">
{{ editing.hasPassword ? 'تغییر رمز عبور' : 'تنظیم رمز عبور' }} {{ editing?.hasPassword ? 'تغییر رمز عبور' : 'تنظیم رمز عبور' }}
</h3> </h3>
<p class="text-xs text-muted"> <p class="text-xs text-muted">
اختیاری — در صورت پر کردن، رمز کاربر بدون نیاز به رمز قبلی تنظیم می‌شود. اختیاری — در صورت پر کردن، رمز کاربر بدون نیاز به رمز قبلی تنظیم می‌شود.
@@ -92,7 +106,9 @@
/> />
</section> </section>
<AppButton type="submit" :loading="saving">ذخیره</AppButton> <AppButton type="submit" :loading="saving">
{{ creating ? 'افزودن کاربر' : 'ذخیره' }}
</AppButton>
</form> </form>
</AppModal> </AppModal>
</AdminLayout> </AdminLayout>
@@ -100,7 +116,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { fetchUsers, setUserPassword, updateUser } from '@/api/users'; import { createUser, fetchUsers, setUserPassword, updateUser } from '@/api/users';
import type { User, UserRole } from '@/api/types'; import type { User, UserRole } from '@/api/types';
import { ApiError } from '@/api/client'; import { ApiError } from '@/api/client';
import AppBadge from '@/components/ui/AppBadge.vue'; import AppBadge from '@/components/ui/AppBadge.vue';
@@ -116,6 +132,7 @@ import SearchInput from '@/components/ui/SearchInput.vue';
import AdminLayout from '@/layouts/AdminLayout.vue'; import AdminLayout from '@/layouts/AdminLayout.vue';
import { activeLabel, roleLabel } from '@/utils/format'; import { activeLabel, roleLabel } from '@/utils/format';
import { filterBySearch } from '@/utils/search'; import { filterBySearch } from '@/utils/search';
import { isValidIranMobile, normalizeIranMobile } from '@/utils/mobile';
const users = ref<User[]>([]); const users = ref<User[]>([]);
const searchQuery = ref(''); const searchQuery = ref('');
@@ -130,9 +147,11 @@ const filteredUsers = computed(() =>
const loading = ref(true); const loading = ref(true);
const error = ref(''); const error = ref('');
const editing = ref<User | null>(null); const editing = ref<User | null>(null);
const creating = ref(false);
const saving = ref(false); const saving = ref(false);
const form = ref({ const form = ref({
mobile: '',
fullName: '', fullName: '',
role: 'customer' as UserRole, role: 'customer' as UserRole,
isActive: true, isActive: true,
@@ -158,9 +177,24 @@ async function load() {
} }
} }
function openCreate() {
creating.value = true;
editing.value = null;
form.value = {
mobile: '',
fullName: '',
role: 'customer',
isActive: true,
password: '',
confirmPassword: '',
};
}
function openEdit(user: User) { function openEdit(user: User) {
creating.value = false;
editing.value = user; editing.value = user;
form.value = { form.value = {
mobile: user.mobile,
fullName: user.fullName ?? '', fullName: user.fullName ?? '',
role: user.role, role: user.role,
isActive: user.isActive, isActive: user.isActive,
@@ -171,9 +205,36 @@ function openEdit(user: User) {
function closeEdit() { function closeEdit() {
editing.value = null; editing.value = null;
creating.value = false;
} }
async function onSave() { async function onSave() {
if (creating.value) {
const mobile = normalizeIranMobile(form.value.mobile);
if (!isValidIranMobile(mobile)) {
error.value = 'شماره موبایل معتبر نیست.';
return;
}
saving.value = true;
error.value = '';
try {
const created = await createUser({
mobile,
fullName: form.value.fullName.trim() || null,
role: form.value.role,
isActive: form.value.isActive,
});
users.value = [created, ...users.value];
closeEdit();
} catch (e) {
error.value = e instanceof ApiError ? e.message : 'خطا در افزودن کاربر';
} finally {
saving.value = false;
}
return;
}
if (!editing.value) return; if (!editing.value) return;
const wantsPassword = Boolean( const wantsPassword = Boolean(