@@ -142,24 +142,15 @@ CommonFunction.install = function (Vue) {
142142 } ,
143143 } ) . then ( function ( resp ) {
144144 func ( resp . data . city , data . IpAdress ) ;
145- console . log ( '留言城市' , resp . data . city ) ;
146- console . log ( '留言ip' , data . IpAdress ) ;
147145 } ) . catch ( ) ;
148146 }
149147 } ) ;
150148 } ;
151149
152- // 获取IP
153- Vue . prototype . GetIp = function ( f ) {
154- this . SQFrontAjax ( {
155- Url : '/api/GetUserIp' ,
156- Success : function ( data ) {
157- f ( data . IpAdress ) ;
158- }
159- } ) ;
160- } ;
161-
162- // 获取当前时间
150+ /**
151+ * 获取当前时间
152+ * @returns {string:2021/11/18 16:45:39 }
153+ */
163154 Vue . prototype . getSQTime = function ( ) {
164155 let dateObject = new Date ( ) ,
165156 year = dateObject . getFullYear ( ) ,
@@ -176,6 +167,36 @@ CommonFunction.install = function (Vue) {
176167 result = '' + year + '/' + month + '/' + day + ' ' + hour + ':' + min + ':' + second ;
177168 return result ;
178169 } ;
170+
171+ /**
172+ * 种cookie
173+ * @param name cookie名称
174+ * @param value cookie值
175+ * @param exHour 过期时间,单位小时
176+ */
177+ Vue . prototype . setSQCookie = function ( name , value , exHour ) {
178+ var d = new Date ( ) ;
179+ d . setTime ( d . getTime ( ) + exHour * 60 * 60 * 1000 ) ;
180+ var expires = 'expires=' + d . toGMTString ( ) ; // cookie的语法要求是这个标志,和这个时间格式
181+ document . cookie = name + '=' + value + '; ' + expires ;
182+ console . log ( '种下cookie' , name + '=' + value + '; ' + expires ) ;
183+ } ;
184+
185+ /**
186+ * 获取cookie
187+ * @param name cookie的名称
188+ */
189+ Vue . prototype . getSQCookie = function ( cookName ) {
190+ let name = cookName + '=' ,
191+ cookies = document . cookie . split ( ';' ) ;
192+ for ( let i = 0 ; i < cookies . length ; i ++ ) {
193+ let cleanItem = cookies [ i ] . trim ( ) ;
194+ if ( cleanItem . indexOf ( name ) == 0 ) {
195+ return cleanItem . substring ( name . length , cookies [ i ] . length ) ;
196+ }
197+ }
198+ return '' ;
199+ } ;
179200} ;
180201
181202export default CommonFunction ;
0 commit comments