|
@@ -25,6 +25,17 @@ import Dialog from '@/components/common/CustomDialog.vue'
|
|
|
import Table from '@/components/table/CustomTable.vue'
|
|
|
import axiosInstance from '@/utils/axios/axiosInstance.ts'
|
|
|
|
|
|
+interface GameInfo {
|
|
|
+ gameName: string
|
|
|
+ gid: string
|
|
|
+ ttAppid: string
|
|
|
+ ttSecret: string
|
|
|
+ wxAppid: string
|
|
|
+ wxSecret: string
|
|
|
+ ttTplId: string
|
|
|
+ wxTplId: string
|
|
|
+}
|
|
|
+
|
|
|
const { allGameInfo } = useCommonStore()
|
|
|
const { AllApi } = useRequest()
|
|
|
|
|
@@ -41,7 +52,7 @@ const requestConfig = reactive({
|
|
|
})
|
|
|
|
|
|
// 表格数据
|
|
|
-const tableData = reactive<Array<any>>([])
|
|
|
+const tableData = reactive<Array<GameInfo>>([])
|
|
|
|
|
|
// 配置分页数据
|
|
|
const paginationConfig: TablePaginationSetting = {
|
|
@@ -149,6 +160,64 @@ const gameFormRule = reactive({
|
|
|
wxSecret: ''
|
|
|
})
|
|
|
|
|
|
+// 判断当前是否是新增弹窗
|
|
|
+// 只有新增的时候才需要校验GID和游戏名是否重复
|
|
|
+const isAddDialog = ref(false)
|
|
|
+
|
|
|
+/**
|
|
|
+ * 校验GID有没有重复
|
|
|
+ *
|
|
|
+ * @param _rule 规则,可忽略
|
|
|
+ * @param value 值
|
|
|
+ * @param callback 回调函数
|
|
|
+ */
|
|
|
+const checkGid = (_rule: any, value: any, callback: any) => {
|
|
|
+ if (!value) {
|
|
|
+ return callback(new Error('请输入游戏ID'))
|
|
|
+ }
|
|
|
+ if (!isAddDialog.value) {
|
|
|
+ callback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ for (let i = 0; i < tableData.length; i++) {
|
|
|
+ if (tableData[i].gid === value) {
|
|
|
+ callback(new Error('游戏ID已存在'))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+ }, 10)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 校验游戏名
|
|
|
+ *
|
|
|
+ * 主要对已经存在的游戏名进行校验
|
|
|
+ *
|
|
|
+ * @param _rule 规则,可忽略
|
|
|
+ * @param value 值
|
|
|
+ * @param callback 回调函数
|
|
|
+ */
|
|
|
+const checkGameName = (_rule: any, value: any, callback: any) => {
|
|
|
+ if (!value) {
|
|
|
+ return callback(new Error('请输入游戏名'))
|
|
|
+ }
|
|
|
+ if (!isAddDialog.value) {
|
|
|
+ callback()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ setTimeout(() => {
|
|
|
+ for (let i = 0; i < tableData.length; i++) {
|
|
|
+ if (tableData[i].gameName === value) {
|
|
|
+ callback(new Error('游戏名已存在'))
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callback()
|
|
|
+ }, 10)
|
|
|
+}
|
|
|
+
|
|
|
// 表单规则
|
|
|
const gameRules = reactive<FormRules<typeof gameFormRule>>({
|
|
|
gameName: [
|
|
@@ -162,6 +231,10 @@ const gameRules = reactive<FormRules<typeof gameFormRule>>({
|
|
|
max: 64,
|
|
|
trigger: 'blur',
|
|
|
message: '最短1位,最长64位'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ validator: checkGameName,
|
|
|
+ trigger: 'blur'
|
|
|
}
|
|
|
],
|
|
|
gid: [
|
|
@@ -175,7 +248,8 @@ const gameRules = reactive<FormRules<typeof gameFormRule>>({
|
|
|
max: 10,
|
|
|
trigger: 'blur',
|
|
|
message: '最短1位,最长10位'
|
|
|
- }
|
|
|
+ },
|
|
|
+ { validator: checkGid, trigger: 'blur' }
|
|
|
],
|
|
|
ttAppid: [
|
|
|
{
|
|
@@ -295,10 +369,12 @@ const gameDialogConfig = reactive<DialogConfig>({
|
|
|
})
|
|
|
|
|
|
const addNewItem = () => {
|
|
|
+ isAddDialog.value = true
|
|
|
gameDialogRef.value.addForm()
|
|
|
}
|
|
|
|
|
|
const handleEdit = (row: any) => {
|
|
|
+ isAddDialog.value = false
|
|
|
gameDialogRef.value.editForm(row)
|
|
|
}
|
|
|
|
|
@@ -314,8 +390,7 @@ const formSub = (formData: any, type: number) => {
|
|
|
game.gameName = formData.gameName
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- gameTableRef.value?.updateTableData()
|
|
|
+ getTableData()
|
|
|
}
|
|
|
|
|
|
const getTableData = async () => {
|