diff --git a/src/main.js b/src/main.js
index a53308c..7cf3beb 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,60 +1,72 @@
-import Vue from 'vue'
+import Vue from "vue";
-import Cookies from 'js-cookie'
+import Cookies from "js-cookie";
-import 'normalize.css/normalize.css'
+import "normalize.css/normalize.css";
-import Element from 'element-ui'
+import Element from "element-ui";
// 数据字典
-import dict from './components/Dict'
-import Editor from "@/components/Editor"
+import dict from "./components/Dict";
+import Editor from "@/components/Editor";
// 权限指令
-import checkPer from '@/utils/permission'
-import permission from './components/Permission'
-import './assets/styles/element-variables.scss'
+import checkPer from "@/utils/permission";
+import permission from "./components/Permission";
+import "./assets/styles/element-variables.scss";
// global css
-import './assets/styles/index.scss'
+import "./assets/styles/index.scss";
-import App from './App'
-import store from './store'
-import router from './router/routers'
+import App from "./App";
+import store from "./store";
+import router from "./router/routers";
-import './assets/icons' // icon
-import './router/index' // permission control
+import "./assets/icons"; // icon
+import "./router/index"; // permission control
// 全局引入
-import EleUploadImage from 'vue-ele-upload-image'
-import VueAMap from 'vue-amap';
+import EleUploadImage from "vue-ele-upload-image";
+import VueAMap from "vue-amap";
-import VueClipboard from 'vue-clipboard2'
+import VueClipboard from "vue-clipboard2";
+import { isPcBowser } from "@/utils/index";
-Vue.component(EleUploadImage.name, EleUploadImage)
-Vue.component('Editor', Editor)
+Vue.component(EleUploadImage.name, EleUploadImage);
+Vue.component("Editor", Editor);
-Vue.use(checkPer)
-Vue.use(permission)
-Vue.use(dict)
+Vue.use(checkPer);
+Vue.use(permission);
+Vue.use(dict);
Vue.use(Element, {
- size: Cookies.get('size') || 'small' // set element-ui default size
-})
-Vue.use(VueAMap)
-Vue.use(VueClipboard)
+ size: Cookies.get("size") || "small" // set element-ui default size
+});
+Vue.use(VueAMap);
+Vue.use(VueClipboard);
+
+Vue.prototype.isPcBowser = isPcBowser();
VueAMap.initAMapApiLoader({
- key: '6033c97e67bf2e9ceac306e1a3fa35f8',
+ key: "6033c97e67bf2e9ceac306e1a3fa35f8",
// securityJsCode: '0547b69252ef0ed14e11f5c4ac152f07',
- plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor']
-})
+ plugin: [
+ "AMap.Autocomplete",
+ "AMap.PlaceSearch",
+ "AMap.Scale",
+ "AMap.OverView",
+ "AMap.ToolBar",
+ "AMap.MapType",
+ "AMap.PolyEditor",
+ "AMap.CircleEditor"
+ ]
+});
-Vue.config.productionTip = false
+Vue.config.productionTip = false;
new Vue({
- el: '#app',
+ el: "#app",
router,
store,
render: h => h(App)
-})
+});
diff --git a/src/utils/index.js b/src/utils/index.js
index 693a50c..7e3ee6b 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -10,22 +10,22 @@
*/
export function parseTime(time, cFormat) {
if (arguments.length === 0) {
- return null
+ return null;
}
- const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
- let date
- if (typeof time === 'undefined' || time === null || time === 'null') {
- return ''
- } else if (typeof time === 'object') {
- date = time
+ const format = cFormat || "{y}-{m}-{d} {h}:{i}:{s}";
+ let date;
+ if (typeof time === "undefined" || time === null || time === "null") {
+ return "";
+ } else if (typeof time === "object") {
+ date = time;
} else {
- if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
- time = parseInt(time)
+ if (typeof time === "string" && /^[0-9]+$/.test(time)) {
+ time = parseInt(time);
}
- if ((typeof time === 'number') && (time.toString().length === 10)) {
- time = time * 1000
+ if (typeof time === "number" && time.toString().length === 10) {
+ time = time * 1000;
}
- date = new Date(time)
+ date = new Date(time);
}
const formatObj = {
y: date.getFullYear(),
@@ -35,17 +35,19 @@ export function parseTime(time, cFormat) {
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]
+ let value = formatObj[key];
// Note: getDay() returns 0 on Sunday
- if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
- if (result.length > 0 && value < 10) {
- value = '0' + value
+ if (key === "a") {
+ return ["日", "一", "二", "三", "四", "五", "六"][value];
}
- return value || 0
- })
- return time_str
+ if (result.length > 0 && value < 10) {
+ value = "0" + value;
+ }
+ return value || 0;
+ });
+ return time_str;
}
/**
@@ -54,40 +56,40 @@ export function parseTime(time, cFormat) {
* @returns {string}
*/
export function formatTime(time, option) {
- if (('' + time).length === 10) {
- time = parseInt(time) * 1000
+ if (("" + time).length === 10) {
+ time = parseInt(time) * 1000;
} else {
- time = +time
+ time = +time;
}
- const d = new Date(time)
- const now = Date.now()
+ const d = new Date(time);
+ const now = Date.now();
- const diff = (now - d) / 1000
+ const diff = (now - d) / 1000;
if (diff < 30) {
- return '刚刚'
+ return "刚刚";
} else if (diff < 3600) {
// less 1 hour
- return Math.ceil(diff / 60) + '分钟前'
+ return Math.ceil(diff / 60) + "分钟前";
} else if (diff < 3600 * 24) {
- return Math.ceil(diff / 3600) + '小时前'
+ return Math.ceil(diff / 3600) + "小时前";
} else if (diff < 3600 * 24 * 2) {
- return '1天前'
+ return "1天前";
}
if (option) {
- return parseTime(time, option)
+ return parseTime(time, option);
} else {
return (
d.getMonth() +
1 +
- '月' +
+ "月" +
d.getDate() +
- '日' +
+ "日" +
d.getHours() +
- '时' +
+ "时" +
d.getMinutes() +
- '分'
- )
+ "分"
+ );
}
}
@@ -96,18 +98,18 @@ export function formatTime(time, option) {
* @returns {Object}
*/
export function getQueryObject(url) {
- url = url == null ? window.location.href : url
- const search = url.substring(url.lastIndexOf('?') + 1)
- const obj = {}
- const reg = /([^?&=]+)=([^?&=]*)/g
+ url = url == null ? window.location.href : url;
+ const search = url.substring(url.lastIndexOf("?") + 1);
+ const obj = {};
+ const reg = /([^?&=]+)=([^?&=]*)/g;
search.replace(reg, (rs, $1, $2) => {
- const name = decodeURIComponent($1)
- let val = decodeURIComponent($2)
- val = String(val)
- obj[name] = val
- return rs
- })
- return obj
+ const name = decodeURIComponent($1);
+ let val = decodeURIComponent($2);
+ val = String(val);
+ obj[name] = val;
+ return rs;
+ });
+ return obj;
}
/**
@@ -116,14 +118,14 @@ export function getQueryObject(url) {
*/
export function byteLength(str) {
// returns the byte length of an utf8 string
- let s = str.length
+ let s = str.length;
for (var i = str.length - 1; i >= 0; i--) {
- const code = str.charCodeAt(i)
- if (code > 0x7f && code <= 0x7ff) s++
- else if (code > 0x7ff && code <= 0xffff) s += 2
- if (code >= 0xDC00 && code <= 0xDFFF) i--
+ const code = str.charCodeAt(i);
+ if (code > 0x7f && code <= 0x7ff) s++;
+ else if (code > 0x7ff && code <= 0xffff) s += 2;
+ if (code >= 0xdc00 && code <= 0xdfff) i--;
}
- return s
+ return s;
}
/**
@@ -131,13 +133,13 @@ export function byteLength(str) {
* @returns {Array}
*/
export function cleanArray(actual) {
- const newArray = []
+ const newArray = [];
for (let i = 0; i < actual.length; i++) {
if (actual[i]) {
- newArray.push(actual[i])
+ newArray.push(actual[i]);
}
}
- return newArray
+ return newArray;
}
/**
@@ -145,13 +147,13 @@ export function cleanArray(actual) {
* @returns {Array}
*/
export function param(json) {
- if (!json) return ''
+ if (!json) return "";
return cleanArray(
Object.keys(json).map(key => {
- if (json[key] === undefined) return ''
- return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
+ if (json[key] === undefined) return "";
+ return encodeURIComponent(key) + "=" + encodeURIComponent(json[key]);
})
- ).join('&')
+ ).join("&");
}
/**
@@ -159,19 +161,19 @@ export function param(json) {
* @returns {Object}
*/
export function param2Obj(url) {
- const search = url.split('?')[1]
+ const search = url.split("?")[1];
if (!search) {
- return {}
+ return {};
}
return JSON.parse(
'{"' +
- decodeURIComponent(search)
- .replace(/"/g, '\\"')
- .replace(/&/g, '","')
- .replace(/=/g, '":"')
- .replace(/\+/g, ' ') +
- '"}'
- )
+ decodeURIComponent(search)
+ .replace(/"/g, '\\"')
+ .replace(/&/g, '","')
+ .replace(/=/g, '":"')
+ .replace(/\+/g, " ") +
+ '"}'
+ );
}
/**
@@ -179,9 +181,9 @@ export function param2Obj(url) {
* @returns {string}
*/
export function html2Text(val) {
- const div = document.createElement('div')
- div.innerHTML = val
- return div.textContent || div.innerText
+ const div = document.createElement("div");
+ div.innerHTML = val;
+ return div.textContent || div.innerText;
}
/**
@@ -191,21 +193,21 @@ export function html2Text(val) {
* @returns {Object}
*/
export function objectMerge(target, source) {
- if (typeof target !== 'object') {
- target = {}
+ if (typeof target !== "object") {
+ target = {};
}
if (Array.isArray(source)) {
- return source.slice()
+ return source.slice();
}
Object.keys(source).forEach(property => {
- const sourceProperty = source[property]
- if (typeof sourceProperty === 'object') {
- target[property] = objectMerge(target[property], sourceProperty)
+ const sourceProperty = source[property];
+ if (typeof sourceProperty === "object") {
+ target[property] = objectMerge(target[property], sourceProperty);
} else {
- target[property] = sourceProperty
+ target[property] = sourceProperty;
}
- })
- return target
+ });
+ return target;
}
/**
@@ -214,18 +216,18 @@ export function objectMerge(target, source) {
*/
export function toggleClass(element, className) {
if (!element || !className) {
- return
+ return;
}
- let classString = element.className
- const nameIndex = classString.indexOf(className)
+ let classString = element.className;
+ const nameIndex = classString.indexOf(className);
if (nameIndex === -1) {
- classString += '' + className
+ classString += "" + className;
} else {
classString =
classString.substr(0, nameIndex) +
- classString.substr(nameIndex + className.length)
+ classString.substr(nameIndex + className.length);
}
- element.className = classString
+ element.className = classString;
}
/**
@@ -233,10 +235,10 @@ export function toggleClass(element, className) {
* @returns {Date}
*/
export function getTime(type) {
- if (type === 'start') {
- return new Date().getTime() - 3600 * 1000 * 24 * 90
+ if (type === "start") {
+ return new Date().getTime() - 3600 * 1000 * 24 * 90;
} else {
- return new Date(new Date().toDateString())
+ return new Date(new Date().toDateString());
}
}
@@ -247,38 +249,38 @@ export function getTime(type) {
* @return {*}
*/
export function debounce(func, wait, immediate) {
- let timeout, args, context, timestamp, result
+ let timeout, args, context, timestamp, result;
- const later = function () {
+ const later = function() {
// 据上一次触发时间间隔
- const last = +new Date() - timestamp
+ const last = +new Date() - timestamp;
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
if (last < wait && last > 0) {
- timeout = setTimeout(later, wait - last)
+ timeout = setTimeout(later, wait - last);
} else {
- timeout = null
+ timeout = null;
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
if (!immediate) {
- result = func.apply(context, args)
- if (!timeout) context = args = null
+ result = func.apply(context, args);
+ if (!timeout) context = args = null;
}
}
- }
+ };
- return function (...args) {
- context = this
- timestamp = +new Date()
- const callNow = immediate && !timeout
+ return function(...args) {
+ context = this;
+ timestamp = +new Date();
+ const callNow = immediate && !timeout;
// 如果延时不存在,重新设定延时
- if (!timeout) timeout = setTimeout(later, wait)
+ if (!timeout) timeout = setTimeout(later, wait);
if (callNow) {
- result = func.apply(context, args)
- context = args = null
+ result = func.apply(context, args);
+ context = args = null;
}
- return result
- }
+ return result;
+ };
}
/**
@@ -289,18 +291,18 @@ export function debounce(func, wait, immediate) {
* @returns {Object}
*/
export function deepClone(source) {
- if (!source && typeof source !== 'object') {
- throw new Error('error arguments', 'deepClone')
+ if (!source && typeof source !== "object") {
+ throw new Error("error arguments", "deepClone");
}
- const targetObj = source.constructor === Array ? [] : {}
+ const targetObj = source.constructor === Array ? [] : {};
Object.keys(source).forEach(keys => {
- if (source[keys] && typeof source[keys] === 'object') {
- targetObj[keys] = deepClone(source[keys])
+ if (source[keys] && typeof source[keys] === "object") {
+ targetObj[keys] = deepClone(source[keys]);
} else {
- targetObj[keys] = source[keys]
+ targetObj[keys] = source[keys];
}
- })
- return targetObj
+ });
+ return targetObj;
}
/**
@@ -308,16 +310,16 @@ export function deepClone(source) {
* @returns {Array}
*/
export function uniqueArr(arr) {
- return Array.from(new Set(arr))
+ return Array.from(new Set(arr));
}
/**
* @returns {string}
*/
export function createUniqueString() {
- const timestamp = +new Date() + ''
- const randomNum = parseInt((1 + Math.random()) * 65536) + ''
- return (+(randomNum + timestamp)).toString(32)
+ const timestamp = +new Date() + "";
+ const randomNum = parseInt((1 + Math.random()) * 65536) + "";
+ return (+(randomNum + timestamp)).toString(32);
}
/**
@@ -327,7 +329,7 @@ export function createUniqueString() {
* @returns {boolean}
*/
export function hasClass(ele, cls) {
- return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
+ return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
}
/**
@@ -336,7 +338,7 @@ export function hasClass(ele, cls) {
* @param {string} cls
*/
export function addClass(ele, cls) {
- if (!hasClass(ele, cls)) ele.className += ' ' + cls
+ if (!hasClass(ele, cls)) ele.className += " " + cls;
}
/**
@@ -346,45 +348,45 @@ export function addClass(ele, cls) {
*/
export function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
- const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
- ele.className = ele.className.replace(reg, ' ')
+ const reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
+ ele.className = ele.className.replace(reg, " ");
}
}
// 替换邮箱字符
export function regEmail(email) {
- if (String(email).indexOf('@') > 0) {
- const str = email.split('@')
- let _s = ''
+ if (String(email).indexOf("@") > 0) {
+ const str = email.split("@");
+ let _s = "";
if (str[0].length > 3) {
for (var i = 0; i < str[0].length - 3; i++) {
- _s += '*'
+ _s += "*";
}
}
- var new_email = str[0].substr(0, 3) + _s + '@' + str[1]
+ var new_email = str[0].substr(0, 3) + _s + "@" + str[1];
}
- return new_email
+ return new_email;
}
// 替换手机字符
export function regMobile(mobile) {
if (mobile.length > 7) {
- var new_mobile = mobile.substr(0, 3) + '****' + mobile.substr(7)
+ var new_mobile = mobile.substr(0, 3) + "****" + mobile.substr(7);
}
- return new_mobile
+ return new_mobile;
}
// 下载文件
export function downloadFile(obj, name, suffix) {
- const url = window.URL.createObjectURL(new Blob([obj]))
- const link = document.createElement('a')
- link.style.display = 'none'
- link.href = url
- const fileName = parseTime(new Date()) + '-' + name + '.' + suffix
- link.setAttribute('download', fileName)
- document.body.appendChild(link)
- link.click()
- document.body.removeChild(link)
+ const url = window.URL.createObjectURL(new Blob([obj]));
+ const link = document.createElement("a");
+ link.style.display = "none";
+ link.href = url;
+ const fileName = parseTime(new Date()) + "-" + name + "." + suffix;
+ link.setAttribute("download", fileName);
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
}
/**
@@ -398,3 +400,19 @@ export function RandomNumBoth(Max, Min = 0) {
var num = Min + Math.round(Rand * Range); //四舍五入
return num;
}
+
+/**
+ * 判断是不是PC浏览器
+ * @returns
+ */
+export function isPcBowser() {
+ if (!window.navigator) {
+ return false;
+ } else {
+ if (/Mobile|Android|webOS|iPhone|iPad|Phone/i.test(navigator.userAgent)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+}
diff --git a/src/views/product/group/index.vue b/src/views/product/group/index.vue
index f0b3e0e..87634f1 100644
--- a/src/views/product/group/index.vue
+++ b/src/views/product/group/index.vue
@@ -18,7 +18,7 @@
- 排序
+ 排序
编辑
@@ -56,9 +56,11 @@ export default {
},
mounted() {
this.getTableData()
- this.$nextTick(() => {
- this.tableDrag()
- })
+ if (this.isPcBowser) {
+ this.$nextTick(() => {
+ this.tableDrag()
+ })
+ }
},
methods: {
//表格拖拽
diff --git a/src/views/product/index.vue b/src/views/product/index.vue
index 1ba27f4..f393d78 100644
--- a/src/views/product/index.vue
+++ b/src/views/product/index.vue
@@ -17,7 +17,7 @@
- 查询
+ 查询
重置
@@ -80,7 +80,7 @@
- 排序
+ 排序
编辑
@@ -125,14 +125,21 @@ export default {
}
}
},
- mounted() {
- this.getTableData()
- this.tbShopCategoryGet()
- this.$nextTick(() => {
- this.tableDrag()
- })
+ async mounted() {
+ await this.tbShopCategoryGet()
+ await this.getTableData()
+ if (this.isPcBowser) {
+ this.$nextTick(() => {
+ this.tableDrag()
+ })
+ }
},
methods: {
+ // 选择分类
+ queryHandle() {
+ localStorage.setItem('shopIndexQuery', JSON.stringify(this.query))
+ this.getTableData()
+ },
//表格拖拽
tableDrag() {
const el = document.querySelector('#table_drag .el-table__body-wrapper tbody')
@@ -177,6 +184,7 @@ export default {
this.query.categoryId = ''
this.query.typeEnum = ''
this.tableData.page = 0
+ localStorage.setItem('shopIndexQuery', JSON.stringify(this.query))
this.getTableData()
},
// 分页回调
@@ -186,8 +194,13 @@ export default {
},
// 获取商品列表
async getTableData() {
- this.tableData.loading = true
try {
+ let localQuery = JSON.parse(localStorage.getItem('shopIndexQuery'))
+ if (localQuery != null) {
+ this.query = localQuery
+ }
+
+ this.tableData.loading = true
const res = await tbProduct({
page: this.tableData.page,
size: this.tableData.size,