离校前端框架,包括数据字典、工作队伍、新闻公告模块
diff --git a/leave-school-vue/src/utils/auth.js b/leave-school-vue/src/utils/auth.js
new file mode 100644
index 0000000..08a43d6
--- /dev/null
+++ b/leave-school-vue/src/utils/auth.js
@@ -0,0 +1,15 @@
+import Cookies from 'js-cookie'
+
+const TokenKey = 'Admin-Token'
+
+export function getToken() {
+ return Cookies.get(TokenKey)
+}
+
+export function setToken(token) {
+ return Cookies.set(TokenKey, token)
+}
+
+export function removeToken() {
+ return Cookies.remove(TokenKey)
+}
diff --git a/leave-school-vue/src/utils/crud.js b/leave-school-vue/src/utils/crud.js
new file mode 100644
index 0000000..70eb9e2
--- /dev/null
+++ b/leave-school-vue/src/utils/crud.js
@@ -0,0 +1,95 @@
+import { MessageBox } from 'element-ui'
+
+export default {
+ data() {
+ return {
+ items: null,
+ recordCount: null,
+ listLoading: true,
+ dialogStatus: '',
+ dialogFormVisible: false,
+ temp: {},
+ textMap: {
+ update: '修改',
+ create: '新增'
+ },
+ dialogPvVisible: false,
+ listQuery: {
+ pageIndex: 1,
+ pageSize: 20
+ },
+ height: 500
+ }
+ }
+}
+
+export function crudPageList(page, _pagelist) {
+ page.listLoading = true
+ _pagelist(Object.assign({}, page.listQuery)).then(response => {
+ page.items = response.items
+ page.listLoading = false
+ page.recordCount = response.recordCount
+ page.pageIndex = response.pageIndex
+ page.pageSize = response.pageSize
+ })
+}
+export function crudGetItem(page, _get, rowid, initData) {
+ if (rowid) {
+ _get({ id: rowid }).then(response => {
+ if (!response.data) {
+ MessageBox.alert('数据不存在,请确认是否已删除。', '消息', {
+ confirmButtonText: '确定'
+ })
+ return
+ }
+ page.temp = response.data
+ page.dialogFormVisible = true
+ page.$nextTick(() => {
+ page.$refs['dataForm'].clearValidate()
+ })
+ })
+ } else {
+ page.temp = Object.assign({}, initData)
+ page.dialogFormVisible = true
+ page.$nextTick(() => {
+ page.$refs['dataForm'].clearValidate()
+ })
+ }
+}
+export function crudCreate(page, _create, _callback) {
+ page.$refs['dataForm'].validate((valid) => {
+ if (valid) {
+ _create(page.temp).then(response => {
+ if (typeof _callback === 'function') {
+ _callback()
+ }
+ page.dialogFormVisible = false
+ page.$notify({
+ title: '成功',
+ message: (page.dialogStatus === 'create') ? '创建成功' : '修改成功',
+ type: 'success',
+ duration: 2000
+ })
+ })
+ }
+ })
+}
+export function crudDelete(page, _delete, rowid, _callback) {
+ MessageBox.confirm('确认删除记录吗?', '删除', {
+ confirmButtonText: '确认',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ _delete({ id: rowid }).then(response => {
+ if (typeof _callback === 'function') {
+ _callback()
+ }
+ page.$notify({
+ title: '成功',
+ message: '删除成功',
+ type: 'success',
+ duration: 2000
+ })
+ })
+ })
+}
diff --git a/leave-school-vue/src/utils/index.js b/leave-school-vue/src/utils/index.js
new file mode 100644
index 0000000..ebe2c42
--- /dev/null
+++ b/leave-school-vue/src/utils/index.js
@@ -0,0 +1,76 @@
+/**
+ * Created by jiachenpan on 16/11/18.
+ */
+
+export function parseTime(time, cFormat) {
+ if (arguments.length === 0) {
+ return null
+ }
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
+ let date
+ if (typeof time === 'object') {
+ date = time
+ } else {
+ if (('' + time).length === 10) time = parseInt(time) * 1000
+ date = new Date(time)
+ }
+ const formatObj = {
+ y: date.getFullYear(),
+ m: date.getMonth() + 1,
+ d: date.getDate(),
+ h: date.getHours(),
+ i: date.getMinutes(),
+ s: date.getSeconds(),
+ a: date.getDay()
+ }
+ const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
+ let value = formatObj[key]
+ if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1]
+ if (result.length > 0 && value < 10) {
+ value = '0' + value
+ }
+ return value || 0
+ })
+ return time_str
+}
+
+export function formatTime(time, option) {
+ time = +time * 1000
+ const d = new Date(time)
+ const now = Date.now()
+
+ const diff = (now - d) / 1000
+
+ if (diff < 30) {
+ return '刚刚'
+ } else if (diff < 3600) { // less 1 hour
+ return Math.ceil(diff / 60) + '分钟前'
+ } else if (diff < 3600 * 24) {
+ return Math.ceil(diff / 3600) + '小时前'
+ } else if (diff < 3600 * 24 * 2) {
+ return '1天前'
+ }
+ if (option) {
+ return parseTime(time, option)
+ } else {
+ return d.getMonth() + 1 + '月' + d.getDate() + '日' + d.getHours() + '时' + d.getMinutes() + '分'
+ }
+}
+
+export function param2Obj(url) {
+ const search = url.split('?')[1]
+ if (!search) {
+ return {}
+ }
+ return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"')
+ .replace(/mapBean%5B/g, '').replace(/%5D/g, '') + '"}')
+}
+
+export function resetForm(listQuery) {
+ for (const attr in listQuery) {
+ if (attr === 'pageIndex' || attr === 'pageSize') {
+ continue
+ }
+ listQuery[attr] = null
+ }
+}
diff --git a/leave-school-vue/src/utils/request.js b/leave-school-vue/src/utils/request.js
new file mode 100644
index 0000000..8b0925b
--- /dev/null
+++ b/leave-school-vue/src/utils/request.js
@@ -0,0 +1,78 @@
+import axios from 'axios'
+import { Message, MessageBox } from 'element-ui'
+import store from '../store'
+import { getToken } from '@/utils/auth'
+
+// 网络请求约定属性名,不可在业务中使用
+const whitelist = ['X-Token', 'token', 'pageIndex', 'pageSize']
+// 创建axios实例
+const service = axios.create({
+ baseURL: process.env.BASE_API, // api的base_url
+ timeout: 10000 // 请求超时时间
+})
+
+// request拦截器
+service.interceptors.request.use(config => {
+ if (store.getters.token) {
+ config.headers['X-Token'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
+ }
+ if (config.params) {
+ for (const attr in config.params) {
+ if (whitelist.indexOf(attr) > -1) {
+ // 约定的属性不用转换
+ continue
+ }
+ config.params[encodeURIComponent('mapBean[' + attr + ']')] = config.params[attr]
+ delete config.params[attr]
+ }
+ }
+ return config
+}, error => {
+ // Do something with request error
+ console.log(error) // for debug
+ Promise.reject(error)
+})
+
+// respone拦截器
+service.interceptors.response.use(
+ response => {
+ /**
+ * code为非20000是抛错 可结合自己业务进行修改
+ */
+ const res = response.data
+ if (response.status !== 200) {
+ Message({
+ message: res.message || '请求失败,状态码:' + res.code,
+ type: 'error',
+ duration: 5 * 1000
+ })
+
+ // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
+ if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
+ MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
+ confirmButtonText: '重新登录',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ store.dispatch('FedLogOut').then(() => {
+ location.reload()// 为了重新实例化vue-router对象 避免bug
+ })
+ })
+ }
+ return Promise.reject('error')
+ } else {
+ return response.data
+ }
+ },
+ error => {
+ console.log('err' + error)// for debug
+ Message({
+ message: error.message,
+ type: 'error',
+ duration: 5 * 1000
+ })
+ return Promise.reject(error)
+ }
+)
+
+export default service
diff --git a/leave-school-vue/src/utils/validate.js b/leave-school-vue/src/utils/validate.js
new file mode 100644
index 0000000..834a8dd
--- /dev/null
+++ b/leave-school-vue/src/utils/validate.js
@@ -0,0 +1,33 @@
+/**
+ * Created by jiachenpan on 16/11/18.
+ */
+
+export function isvalidUsername(str) {
+ const valid_map = ['admin', 'editor']
+ return valid_map.indexOf(str.trim()) >= 0
+}
+
+/* 合法uri*/
+export function validateURL(textval) {
+ const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
+ return urlregex.test(textval)
+}
+
+/* 小写字母*/
+export function validateLowerCase(str) {
+ const reg = /^[a-z]+$/
+ return reg.test(str)
+}
+
+/* 大写字母*/
+export function validateUpperCase(str) {
+ const reg = /^[A-Z]+$/
+ return reg.test(str)
+}
+
+/* 大小写字母*/
+export function validatAlphabets(str) {
+ const reg = /^[A-Za-z]+$/
+ return reg.test(str)
+}
+