|
@@ -35,55 +35,111 @@
|
|
</el-col>
|
|
</el-col>
|
|
</div>
|
|
</div>
|
|
<el-dialog v-model="data.dialog" title="项目管理" :before-close="handleClose">
|
|
<el-dialog v-model="data.dialog" title="项目管理" :before-close="handleClose">
|
|
- <Form @submitForm="submitForm" :ruleForm="ruleForm"></Form>
|
|
|
|
|
|
+ <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="120px" class="demo-ruleForm" :size="formSize" status-icon>
|
|
|
|
+ <el-form-item label="项目名" prop="name">
|
|
|
|
+ <el-input v-model="ruleForm.name" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="描述" prop="desc">
|
|
|
|
+ <el-input v-model="ruleForm.desc" type="textarea" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="备注" prop="remarks">
|
|
|
|
+ <el-input v-model="ruleForm.remark" type="textarea" />
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item>
|
|
|
|
+ <el-button type="primary" @click="submitForm(ruleFormRef)"> 提交 </el-button>
|
|
|
|
+ <el-button @click="resetForm(ruleFormRef)">重置</el-button>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-form>
|
|
</el-dialog>
|
|
</el-dialog>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
import { reactive, ref } from 'vue';
|
|
import { reactive, ref } from 'vue';
|
|
-import Form from '@/layout/homeParts/form-1.vue';
|
|
|
|
import { useCounterStore as useStore } from '@/stores/counter';
|
|
import { useCounterStore as useStore } from '@/stores/counter';
|
|
import type { IQueryResult } from '@/util/types.util';
|
|
import type { IQueryResult } from '@/util/types.util';
|
|
|
|
+import type { FormInstance, FormRules } from 'element-plus';
|
|
|
|
+import { ElMessage, ElMessageBox } from 'element-plus';
|
|
const store = useStore();
|
|
const store = useStore();
|
|
|
|
|
|
|
|
+const formSize = ref('default');
|
|
|
|
+const ruleFormRef = ref<FormInstance>();
|
|
|
|
+// 表单
|
|
|
|
+let ruleForm = reactive({
|
|
|
|
+ name: '',
|
|
|
|
+ remark: '',
|
|
|
|
+ desc: '',
|
|
|
|
+});
|
|
|
|
+// 验证
|
|
|
|
+const rules = reactive<FormRules>({
|
|
|
|
+ name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
|
|
|
|
+});
|
|
|
|
+
|
|
// #region 1
|
|
// #region 1
|
|
const data = reactive({
|
|
const data = reactive({
|
|
id: '',
|
|
id: '',
|
|
dialog: ref(false),
|
|
dialog: ref(false),
|
|
});
|
|
});
|
|
let items: any = reactive([]);
|
|
let items: any = reactive([]);
|
|
-let ruleForm: Object = reactive({
|
|
|
|
- _id: '',
|
|
|
|
- name: '',
|
|
|
|
- desc: '',
|
|
|
|
- remarks: '',
|
|
|
|
-});
|
|
|
|
|
|
+// 请求列表
|
|
const res: IQueryResult = await store.projectQuery();
|
|
const res: IQueryResult = await store.projectQuery();
|
|
items = res.data;
|
|
items = res.data;
|
|
|
|
|
|
const emit = defineEmits(['onMenu']);
|
|
const emit = defineEmits(['onMenu']);
|
|
|
|
+// 点击菜单
|
|
const onMenu = (item: { _id: string; name: string }) => {
|
|
const onMenu = (item: { _id: string; name: string }) => {
|
|
data['id'] = item._id;
|
|
data['id'] = item._id;
|
|
emit('onMenu', item);
|
|
emit('onMenu', item);
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+// 添加
|
|
const toAdd = async (type: string) => {
|
|
const toAdd = async (type: string) => {
|
|
if (type == 'edit') {
|
|
if (type == 'edit') {
|
|
const aee: IQueryResult = await store.projectFetch(data.id);
|
|
const aee: IQueryResult = await store.projectFetch(data.id);
|
|
|
|
+ console.log(aee.data);
|
|
ruleForm = aee.data;
|
|
ruleForm = aee.data;
|
|
} else if (type == 'add') {
|
|
} else if (type == 'add') {
|
|
- ruleForm = {};
|
|
|
|
|
|
+ ruleForm = { name: '', desc: '', remark: '' };
|
|
}
|
|
}
|
|
data.dialog = true;
|
|
data.dialog = true;
|
|
};
|
|
};
|
|
-const submitForm = () => {
|
|
|
|
- console.log(ruleForm);
|
|
|
|
|
|
+// 提交保存
|
|
|
|
+const submitForm = async (formEl: FormInstance | undefined) => {
|
|
|
|
+ if (!formEl) return;
|
|
|
|
+ await formEl.validate(async (valid, fields) => {
|
|
|
|
+ if (valid) {
|
|
|
|
+ const res: IQueryResult = await store.projectCreate(ruleForm);
|
|
|
|
+ if (res.errcode == 0) {
|
|
|
|
+ // 重新请求列表
|
|
|
|
+ // const aee: IQueryResult = await store.projectQuery();
|
|
|
|
+ // items = aee.data;
|
|
|
|
+ handleClose();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
};
|
|
};
|
|
|
|
+// 重置
|
|
|
|
+const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
|
+ if (!formEl) return;
|
|
|
|
+ formEl.resetFields();
|
|
|
|
+};
|
|
|
|
+// 关闭弹窗
|
|
const handleClose = () => {
|
|
const handleClose = () => {
|
|
- console.log(ruleForm);
|
|
|
|
-
|
|
|
|
|
|
+ ruleForm = { name: '', desc: '', remark: '' };
|
|
data.dialog = false;
|
|
data.dialog = false;
|
|
};
|
|
};
|
|
-const toDelete = () => {};
|
|
|
|
|
|
+// 删除;
|
|
|
|
+const toDelete = async () => {
|
|
|
|
+ ElMessageBox.confirm('是否确认删除该项目', '提示', {
|
|
|
|
+ confirmButtonText: '确认',
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
+ type: 'warning',
|
|
|
|
+ }).then(async () => {
|
|
|
|
+ const res: IQueryResult = await store.projecDelete(data.id);
|
|
|
|
+ if (res.errcode == 0) {
|
|
|
|
+ ElMessage({ type: 'success', message: '删除成功' });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+};
|
|
// #endregion
|
|
// #endregion
|
|
</script>
|
|
</script>
|
|
|
|
|